Skip to content

Commit

Permalink
Fix OnSendToServer, memory increased
Browse files Browse the repository at this point in the history
  • Loading branch information
GuckTubeYT authored Feb 23, 2023
1 parent 09e972d commit 5a58708
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions eventClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "proxyStruct.h"

void clientConnect() {
if (OnPacket.OnSendToServer) {
if (isSendToServer) {
printf("[Client] Client connected into proxy\n[Client] Connecting to subserver...\n");
enet_host_destroy(realServer);

Expand All @@ -26,7 +26,7 @@ void clientConnect() {
free(OnSendToServer.serverAddress);
free(OnSendToServer.UUIDToken);

OnPacket.OnSendToServer = 0;
isSendToServer = 0;
} else {
printf("[Client] Client connected into proxy\n[Client] Connecting to Growtopia Server...\n");

Expand Down
21 changes: 15 additions & 6 deletions eventServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void serverReceive(ENetEvent event, ENetPeer* clientPeer, ENetPeer* serverPeer)
}
case 4: {
if (OnPacket.OnSendToServer) {
asprintf(&OnSendToServer.rawSplit, "%s", value);
char** toSplit = strsplit(value, "|", 0);
asprintf(&OnSendToServer.serverAddress, "%s", toSplit[0]);
asprintf(&OnSendToServer.UUIDToken, "%s", toSplit[2]);
Expand Down Expand Up @@ -118,8 +119,12 @@ void serverReceive(ENetEvent event, ENetPeer* clientPeer, ENetPeer* serverPeer)
if (OnPacket.OnSendToServer) OnSendToServer.userID = value;
break;
}
case 5: {
if (OnPacket.OnSendToServer) OnSendToServer.unkInt = value;
break;
}
}

printf("[Server] TankUpdatePacket Variable: integer found at %d: %d\n", index, value);
break;
}
Expand All @@ -130,10 +135,14 @@ void serverReceive(ENetEvent event, ENetPeer* clientPeer, ENetPeer* serverPeer)
}
}
if (OnPacket.OnSendToServer) {
char* tempString;
asprintf(&tempString, "127.0.0.1|0|%s", OnSendToServer.UUIDToken);
enet_peerSend(onPacketCreate("sdddsd", "OnSendToServer", 17091, OnSendToServer.token, OnSendToServer.userID, tempString, 1), clientPeer);
free(tempString);
printf("%s\n", OnSendToServer.rawSplit);
char** splitString = strsplit(OnSendToServer.rawSplit, "|", 0);
splitString[0] = "127.0.0.1";
enet_peerSend(onPacketCreate("sdddsd", "OnSendToServer", 17091, OnSendToServer.token, OnSendToServer.userID, arrayJoin(splitString, "|"), OnSendToServer.unkInt), clientPeer);
free(splitString);
free(OnSendToServer.rawSplit);
OnPacket.OnSendToServer = 0;
isSendToServer = 1;
} else enet_peerSend(event.packet, clientPeer);
break;
}
Expand All @@ -155,4 +164,4 @@ void serverReceive(ENetEvent event, ENetPeer* clientPeer, ENetPeer* serverPeer)

void serverDisconnect() {
printf("[Server] Proxy just disconnected from Server\n");
}
}
3 changes: 2 additions & 1 deletion externInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pthread_t HTTPThread;

char isLoop;
char doLoop;
char isSendToServer;
char HTTPAlreadyOn;

struct currentInfo_ currentInfo;
Expand All @@ -25,4 +26,4 @@ ENetPeer* realPeer;
ENetAddress realAddress;
ENetHost* proxyServer;
ENetPeer* proxyPeer;
ENetAddress proxyAddress;
ENetAddress proxyAddress;
9 changes: 5 additions & 4 deletions httpService.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ int send_pending(int client_sock, struct TLSContext *context) {
}

struct HTTPInfo HTTPSClient(const char* website) {
unsigned char read_buffer[0xFFFF];
unsigned char client_message[0xFFFF];

int sockfd, portno = 443;
struct sockaddr_in serv_addr;
struct hostent *server;
struct HTTPInfo info;
unsigned char read_buffer[0xFFFF];

#ifdef _WIN32
WSADATA wsaData;
Expand Down Expand Up @@ -120,7 +122,7 @@ struct HTTPInfo HTTPSClient(const char* website) {
tls_make_exportable(context, 1);
tls_client_connect(context);
send_pending(sockfd, context);
unsigned char client_message[0xFFFF];

int read_size;
while ((read_size = recv(sockfd, client_message, sizeof(client_message), 0)) > 0) {
tls_consume_stream(context, client_message, read_size, NULL);
Expand All @@ -138,14 +140,14 @@ struct HTTPInfo HTTPSClient(const char* website) {
}
read_buffer[info.bufferLen] = '\0';
info.buffer = read_buffer;
SSL_CTX_free(context);
return info;
}

void HTTPSServer(void* unused) {
int socket_desc, client_sock;
socklen_t c;
struct sockaddr_in server, client;
char client_message[0xFFFF];
const char msg[] = "HTTP/1.1 200 OK\r\nContent-length: 279\r\n\r\nserver|127.0.0.1\nport|17091\ntype|1\n#maint|maintenance\nbeta_server|beta.growtopiagame.com\nbeta_port|26999\nbeta_type|1\nbeta2_server|beta2.growtopiagame.com\nbeta2_port|26999\nbeta2_type|1\nbeta3_server|34.202.7.77\nbeta3_port|26999\nbeta3_type|1\ntype2|0\nmeta|localhost\nRTENDMARKERBS1001";

#ifdef _WIN32
Expand Down Expand Up @@ -209,7 +211,6 @@ void HTTPSServer(void* unused) {
SSL_set_fd(client, client_sock);

if (SSL_accept(client)) {
SSL_read(client, client_message, sizeof(client_message));
if (SSL_write(client, msg, strlen(msg)) < 0) printf("[HTTPService Server] Error: in SSL Write\n");
} else printf("[HTTPService Server] Error: in handshake\n");
SSL_shutdown(client);
Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main() {
while(isLoop) {
ENetEvent proxyEvent;
ENetEvent realEvent;
while(enet_host_service(proxyServer, &proxyEvent, 0) > 0) {
while(enet_host_service(proxyServer, &proxyEvent, 5) > 0) {
proxyPeer = proxyEvent.peer;
switch(proxyEvent.type) {
case ENET_EVENT_TYPE_CONNECT: {
Expand All @@ -76,7 +76,7 @@ int main() {
}
}

while(enet_host_service(realServer, &realEvent, 0) > 0) {
while(enet_host_service(realServer, &realEvent, 5) > 0) {
switch(realEvent.type) {
case ENET_EVENT_TYPE_CONNECT: {
serverConnect();
Expand Down
2 changes: 1 addition & 1 deletion mainVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ extern char isLoop;
extern char doLoop;
extern char HTTPAlreadyOn;

#endif // MAINVAR_H
#endif // MAINVAR_H
6 changes: 5 additions & 1 deletion proxyStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ struct OnSendToServer_{
int token;
int userID;
char* UUIDToken;
int unkInt;
char* rawSplit;
};

extern struct currentInfo_ currentInfo;
extern struct OnPacket_ OnPacket;
extern struct OnConsoleMessage_ OnConsoleMessage;
extern struct OnSendToServer_ OnSendToServer;

#endif // PROXYSTRUCT_H
extern char isSendToServer;

#endif // PROXYSTRUCT_H

0 comments on commit 5a58708

Please sign in to comment.