/* ** inserts a new key into a hash table; first, check whether key's main ** position is free. If not, check whether colliding node is in its main ** position or not: if it is not, move colliding node to an empty place and ** put new key in its main position; otherwise (colliding node is in its main ** position), new key goes to an empty position. */ static TableNode* table_newkey(Table *t, uint32_t key) { TableNode *mp = mainposition(t, key); if(!tisnil(mp)) { TableNode *n = getfreenode(t); if(n == NULL) { table_expand(t); return table_newkey(t, key); } TableNode *othern = mainposition(t, mp->key); if (othern != mp) { int mindex = tindex(t, mp); while(othern->next != mindex) { othern = tnode(t, othern->next); } othern->next = tindex(t, n); *n = *mp; initnode(mp); } else { n->next = mp->next; mp->next = tindex(t, n); mp = n; } } mp->key = key; mp->flag = 'n'; return mp; }
static void SOCK_Get(void) { size_t i, n; int j; ssize_t c; mysockaddr_t fromaddress; socklen_t fromlen; for (n = 0; n < mysocketses; n++) { fromlen = (socklen_t)sizeof(fromaddress); c = recvfrom(mysockets[n], (char *)&doomcom->data, MAXPACKETLENGTH, 0, (void *)&fromaddress, &fromlen); if (c != ERRSOCKET) { // find remote node number for (j = 0; j <= MAXNETNODES; j++) //include LAN { if (SOCK_cmpaddr(&fromaddress, &clientaddress[j], 0)) { doomcom->remotenode = (INT16)j; // good packet from a game player doomcom->datalength = (INT16)c; nodesocket[j] = mysockets[n]; return; } } // not found // find a free slot cleanupnodes(); j = getfreenode(); if (j > 0) { M_Memcpy(&clientaddress[j], &fromaddress, fromlen); nodesocket[j] = mysockets[n]; DEBFILE(va("New node detected: node:%d address:%s\n", j, SOCK_GetNodeAddress(j))); doomcom->remotenode = (INT16)j; // good packet from a game player doomcom->datalength = (INT16)c; // check if it's a banned dude so we can send a refusal later for (i = 0; i < numbans; i++) { if (SOCK_cmpaddr(&fromaddress, &banned[i], bannedmask[i])) { SOCK_bannednode[j] = true; DEBFILE("This dude has been banned\n"); break; } } if (i == numbans) SOCK_bannednode[j] = false; return; } else DEBFILE("New node detected: No more free slots\n"); } } doomcom->remotenode = -1; // no packet }