DEADSOFTWARE

Больше проверок корректности пакетов на стороне сервера
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 5 Apr 2017 19:10:11 +0000 (22:10 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 5 Apr 2017 19:10:11 +0000 (22:10 +0300)
netwar.c
server.c

index b7c2222b212be1a1511e8a0af5167770053ab1a6..e18438e8a650fd59003429dea65e3ba3ea91c6cc 100644 (file)
--- a/netwar.c
+++ b/netwar.c
@@ -117,8 +117,8 @@ static void paintwindow() {
        SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0xFF, 0x00);
 
        static float start_r;
-       for(int i = 0; i < STAR_SIZE * 200; i++)
-               paintmodel(star, sizeof(star), 0, 0, M_PI / i + start_r, STAR_SIZE, cx, cy);
+       for(int i = 0; i < STAR_SIZE * 150; i++)
+               paintmodel(star, sizeof(star), 0, 0, start_r + i * M_PI, STAR_SIZE, cx, cy);
 
        start_r += 0.0001;
 
index e60ac264fdffb1ac32881cf4bd0812542baba512..38c6790f9ba58a05819bd7f702ccd08baeb49e15 100644 (file)
--- a/server.c
+++ b/server.c
@@ -84,24 +84,29 @@ static void sv_move_player(int id, ProtocolMessage m) {
        g_player_does(id, m.cl.does.code);
 }
 
-static void sv_register_player(IPaddress address, ProtocolMessage m) {
-       if(m.cl.info.version != PROTOCOL_VERSION)
-               SendMessage(sock, address, sv_kill("Uncompatible version"));
+static void sv_kill_address(IPaddress address, const char * msg) {
+       SDL_Log("sv_kill_address: %s", msg);
+       SendMessage(sock, address, sv_kill(msg));
+}
+
+static void sv_register_player(IPaddress address, ClInfo info) {
+       if(info.version != PROTOCOL_VERSION) {
+               sv_kill_address(address, "Uncompatible version");
+               return;
+       }
 
        int i = 0;
        while((i < clientlimit) && (client[i].connected))
                ++i;
 
-       int namesize = sizeof(m.cl.info.name);
        if(i >= clientlimit) {
-               SDL_Log("Too may clints, player %.*s disconnected", namesize, m.cl.info.name);
-               SendMessage(sock, address, sv_kill("Too many clients"));
+               sv_kill_address(address, "Too many clients");
                return;
        }
 
        client[i].connected = true;
        client[i].address   = address;
-       strncpy(client[i].name, (char*) m.cl.info.name, MAX_NAMESIZE);
+       strncpy(client[i].name, (char*) info.name, MAX_NAMESIZE);
        client[i].name[MAX_NAMESIZE - 1] = 0;
 
        SDL_Log("Player %s (%i) connected", client[i].name, i);
@@ -111,17 +116,24 @@ static void sv_register_player(IPaddress address, ProtocolMessage m) {
        sv_sync_client(i, true);
 }
 
+static void sv_recv_ipmsg(IPaddress address, ProtocolMessage m) {
+       int id = sv_find_client(address);
+       if(id < 0 && m.type != CL_INFO)
+               return;
+
+       switch(m.type) {
+       case CL_INFO: sv_register_player(address, m.cl.info); break;
+       case CL_KILL: sv_kill_player(id, false, "");  break;
+       case CL_DOES: sv_move_player(id, m);          break;
+       default:      sv_kill_address(address, "Invalid message");
+       }
+}
+
 static void sv_recv() {
        IPaddress address;
        ProtocolMessage m;
-       while(RecvMessage(sock, &address, &m)) {
-               switch(m.type) {
-               case CL_INFO: sv_register_player(address, m); break;
-               case CL_KILL: sv_kill_player(sv_find_client(address), false, ""); break;
-               case CL_DOES: sv_move_player(sv_find_client(address), m); break;
-               default:      SDL_Log("invalid message %i", m.type);
-               }
-       }
+       while(RecvMessage(sock, &address, &m))
+               sv_recv_ipmsg(address, m);
 }
 
 static void sv_send() {