… | |
… | |
65 | * before player joins, and those happen after the player has joined. |
65 | * before player joins, and those happen after the player has joined. |
66 | * As such, we have function types that might be called, so |
66 | * As such, we have function types that might be called, so |
67 | * we end up having 2 tables. |
67 | * we end up having 2 tables. |
68 | */ |
68 | */ |
69 | |
69 | |
70 | typedef void (*func_uint8_int_ns) (char *, int, NewSocket *); |
70 | typedef void (*func_uint8_int_ns) (char *, int, client_socket *); |
71 | |
71 | |
72 | struct NsCmdMapping |
72 | struct NsCmdMapping |
73 | { |
73 | { |
74 | const char *cmdname; |
74 | const char *cmdname; |
75 | func_uint8_int_ns cmdproc; |
75 | func_uint8_int_ns cmdproc; |
… | |
… | |
132 | * RequestInfo is sort of a meta command. There is some specific |
132 | * RequestInfo is sort of a meta command. There is some specific |
133 | * request of information, but we call other functions to provide |
133 | * request of information, but we call other functions to provide |
134 | * that information. |
134 | * that information. |
135 | */ |
135 | */ |
136 | void |
136 | void |
137 | RequestInfo (char *buf, int len, NewSocket * ns) |
137 | RequestInfo (char *buf, int len, client_socket * ns) |
138 | { |
138 | { |
139 | char *params = NULL, *cp; |
139 | char *params = NULL, *cp; |
140 | |
140 | |
141 | /* No match */ |
141 | /* No match */ |
142 | char bigbuf[MAX_BUF]; |
142 | char bigbuf[MAX_BUF]; |
… | |
… | |
167 | else if (!strcmp (buf, "skill_info")) |
167 | else if (!strcmp (buf, "skill_info")) |
168 | send_skill_info (ns, params); |
168 | send_skill_info (ns, params); |
169 | else if (!strcmp (buf, "spell_paths")) |
169 | else if (!strcmp (buf, "spell_paths")) |
170 | send_spell_paths (ns, params); |
170 | send_spell_paths (ns, params); |
171 | else |
171 | else |
172 | Write_String_To_Socket (ns, bigbuf, len); |
172 | ns->send_packet (bigbuf, len); |
173 | } |
173 | } |
174 | |
174 | |
175 | /** |
175 | /** |
176 | * Handle client input. |
176 | * Handle client input. |
177 | * |
177 | * |
… | |
… | |
181 | * with this socket, null if no player (one of the init_sockets for just |
181 | * with this socket, null if no player (one of the init_sockets for just |
182 | * starting a connection) |
182 | * starting a connection) |
183 | */ |
183 | */ |
184 | |
184 | |
185 | void |
185 | void |
186 | HandleClient (NewSocket *ns, player *pl) |
186 | HandleClient (client_socket *ns, player *pl) |
187 | { |
187 | { |
188 | /* Loop through this - maybe we have several complete packets here. */ |
188 | /* Loop through this - maybe we have several complete packets here. */ |
189 | // limit to a few commands only, though, as to not monopolise the server |
189 | // limit to a few commands only, though, as to not monopolise the server |
190 | for (int repeat = 16; repeat--;) |
190 | for (int repeat = 16; repeat--;) |
191 | { |
191 | { |
… | |
… | |
424 | LOG (llevDebug, "doeric_server: New Connection\n"); |
424 | LOG (llevDebug, "doeric_server: New Connection\n"); |
425 | #endif |
425 | #endif |
426 | /* If this is the case, all sockets currently in used */ |
426 | /* If this is the case, all sockets currently in used */ |
427 | if (socket_info.allocated_sockets <= socket_info.nconns) |
427 | if (socket_info.allocated_sockets <= socket_info.nconns) |
428 | { |
428 | { |
429 | init_sockets = (NewSocket *) realloc (init_sockets, sizeof (NewSocket) * (socket_info.nconns + 1)); |
429 | init_sockets = (client_socket *) realloc (init_sockets, sizeof (client_socket) * (socket_info.nconns + 1)); |
430 | if (!init_sockets) |
430 | if (!init_sockets) |
431 | fatal (OUT_OF_MEMORY); |
431 | fatal (OUT_OF_MEMORY); |
432 | newsocknum = socket_info.allocated_sockets; |
432 | newsocknum = socket_info.allocated_sockets; |
433 | socket_info.allocated_sockets++; |
433 | socket_info.allocated_sockets++; |
434 | init_sockets[newsocknum].faces_sent_len = nrofpixmaps; |
434 | init_sockets[newsocknum].faces_sent_len = nrofpixmaps; |
… | |
… | |
455 | LOG (llevError, "accept failed: %s\n", strerror (errno)); |
455 | LOG (llevError, "accept failed: %s\n", strerror (errno)); |
456 | else |
456 | else |
457 | { |
457 | { |
458 | char buf[MAX_BUF]; |
458 | char buf[MAX_BUF]; |
459 | long ip; |
459 | long ip; |
460 | NewSocket *ns; |
460 | client_socket *ns; |
461 | |
461 | |
462 | ns = &init_sockets[newsocknum]; |
462 | ns = &init_sockets[newsocknum]; |
463 | |
463 | |
464 | ip = ntohl (addr.sin_addr.s_addr); |
464 | ip = ntohl (addr.sin_addr.s_addr); |
465 | sprintf (buf, "%ld.%ld.%ld.%ld", (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255); |
465 | sprintf (buf, "%ld.%ld.%ld.%ld", (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255); |
… | |
… | |
470 | close (init_sockets[newsocknum].fd); |
470 | close (init_sockets[newsocknum].fd); |
471 | init_sockets[newsocknum].fd = -1; |
471 | init_sockets[newsocknum].fd = -1; |
472 | } |
472 | } |
473 | else |
473 | else |
474 | { |
474 | { |
475 | InitConnection (ns, buf); |
475 | ns->init (buf); |
476 | socket_info.nconns++; |
476 | socket_info.nconns++; |
477 | } |
477 | } |
478 | } |
478 | } |
479 | } |
479 | } |
480 | |
480 | |