void AddToFileSource(source_data *source, server_data *serv) { if (IsInSource(source, serv)) return; SB_ServerList_Lock(); // reallocate buffer if we've run out of space if (source->serversn >= source->servers_allocated) { int new_size = source->servers_allocated + 4; server_data** newlist = Q_malloc(new_size * sizeof(server_data*)); memcpy(newlist, source->servers, sizeof(server_data*) * source->servers_allocated); Q_free(source->servers); source->servers = newlist; source->servers_allocated = new_size; } source->servers[source->serversn++] = Clone_Server(serv); rebuild_servers_list = true; SB_ServerList_Unlock(); DumpSource(source); Mark_Source(sources[0]); }
void RemoveFromFileSource(source_data *source, server_data *serv) { int i; if (source->serversn <= 0) return; for (i=0; i < source->serversn; i++) if (!memcmp(&source->servers[i]->address, &serv->address, 6)) { // add to unbound AddUnbound(serv); // remove from source if (i != source->serversn - 1) { memmove(source->servers+i, source->servers+i+1, (source->serversn - i - 1) * sizeof(source_data *)); } (source->serversn) --; DumpSource(source); Mark_Source(sources[0]); return; } }
void AddToFileSource(source_data *source, server_data *serv) { if (IsInSource(source, serv)) return; source->servers[source->serversn] = serv; (source->serversn) ++; rebuild_servers_list = true; DumpSource(source); Mark_Source(sources[0]); }
void DlgCmd( void ) { char buff[256]; printf( "DBG>" ); fflush( stdout ); // not really necessary gets( buff ); if( buff[0] != NULLCHAR && buff[1] == NULLCHAR ) { switch( tolower( buff[0] ) ) { case 'u': WndAsmInspect( GetCodeDot() ); break; case 's': DumpSource(); break; case 'l': DumpLocals(); break; case 'i': RunRequest( REQ_TRACE_INTO ); break; case 'o': RunRequest( REQ_TRACE_OVER ); break; case 'g': RunRequest( REQ_GO ); break; case 'x': if( _IsOn( SW_REMOTE_LINK ) ) { printf( "Can't break remote task!\n" ); } else { HMODULE hmod; PFN proc = NULL; DosQueryModuleHandle( TrapParms, &hmod ); DosQueryProcAddr( hmod, 5, 0, &proc ); // if( proc != NULL ) // proc(); } // break the task break; default: printf( "Error - unrecognized command\n" ); } } else { DoCmd( DupStr( buff ) ); DoInput(); } }
void DlgCmd( void ) { char buff[256]; printf( "DBG>" ); fflush( stdout ); gets( buff ); if( buff[0] != NULLCHAR && buff[1] == NULLCHAR ) { switch( tolower( buff[0] ) ) { case 'u': WndAsmInspect( GetCodeDot() ); break; case 's': DumpSource(); break; case 'l': DumpLocals(); break; case 'i': RunRequest( REQ_TRACE_INTO ); break; case 'o': RunRequest( REQ_TRACE_OVER ); break; case 'g': RunRequest( REQ_GO ); break; case 'x': if( _IsOn( SW_REMOTE_LINK ) ) { printf( "Can't break remote task!\n" ); } else { HANDLE hmod; FARPROC proc; hmod = GetModuleHandle( TrapParms ); proc = GetProcAddress( hmod, (LPSTR)5 ); if( proc != NULL ) proc(); CloseHandle( hmod ); } // break the task break; default: printf( "Error - unrecognized command\n" ); } } else { DoCmd( DupStr( buff ) ); DoInput(); } }
void RemoveFromFileSource(source_data *source, server_data *serv) { int i; if (source->serversn <= 0) return; for (i=0; i < source->serversn; i++) if (!memcmp(&source->servers[i]->address, &serv->address, 6)) { // Only add to unbound if not in any other sources... int j = 0; qbool in_other_source = false; for (j = 0; j < sourcesn; ++j) { if (source != sources[j]) { in_other_source |= IsInSource(sources[j], serv); } } // remove from source if (i != source->serversn - 1) { memmove(source->servers+i, source->servers+i+1, (source->serversn - i - 1) * sizeof(source_data *)); } --source->serversn; DumpSource(source); if (!in_other_source) { // add to unbound AddUnbound(serv); Mark_Source(sources[0]); } return; } }
DWORD WINAPI Update_Multiple_Sources_Proc(void * lpParameter) { // get servers from master server SYSTEMTIME lt; char request[] = {'c', '\n', '\0'}; socket_t newsocket; struct sockaddr_storage server; int ret = 0, i, sourcenum; unsigned char answer[10000]; fd_set fd; struct timeval tv; int total_masters = 0; int updated = 0; int d1, d2; GetLocalTime(<); d1 = lt.wSecond + 60*(lt.wMinute + 60*(lt.wHour + 24*(lt.wDay))); // update file sources - this should be a flash for (sourcenum = 0; sourcenum < psourcesn; sourcenum++) if (psources[sourcenum]->checked) { if (psources[sourcenum]->type == type_file) Update_Source(psources[sourcenum]); if (psources[sourcenum]->type == type_url) Update_Source(psources[sourcenum]); // todo cache this too else if (psources[sourcenum]->type == type_master) { source_data *s = psources[sourcenum]; if (s->last_update.wYear != 0 && !source_full_update) { d2 = s->last_update.wSecond + 60*(s->last_update.wMinute + 60*(s->last_update.wHour + 24*(s->last_update.wDay))); if (d1 > d2 && d1 < d2 + sb_sourcevalidity.value*60) continue; } total_masters++; } } // update master sources newsocket = UDP_OpenSocket(PORT_ANY); for (sourcenum = 0; sourcenum < psourcesn && !abort_ping; sourcenum++) { server_data *servers[MAX_SERVERS]; int serversn = 0; int trynum = 0; source_data *s = psources[sourcenum]; double timeout; if (psources[sourcenum]->type != type_master || !psources[sourcenum]->checked) continue; if (s->last_update.wYear != 0 && !source_full_update) { d2 = s->last_update.wSecond + 60*(s->last_update.wMinute + 60*(s->last_update.wHour + 24*(s->last_update.wDay))); if (d1 > d2 && d1 < d2 + sb_sourcevalidity.value*60) continue; } // send trynum queries to master server for (trynum=0; trynum < sb_masterretries.value; trynum++) { NetadrToSockadr (&(s->address.address), &server); ret = sendto (newsocket, request, sizeof(request), 0, (struct sockaddr *)&server, sizeof(server) ); } if (ret <= 0) continue; timeout = Sys_DoubleTime() + (sb_mastertimeout.value / 1000.0); while (Sys_DoubleTime() < timeout) { struct sockaddr_storage hostaddr; netadr_t from; //fd.fd_count = 1; //fd.fd_array[0] = newsocket; FD_ZERO(&fd); FD_SET(newsocket, &fd); tv.tv_sec = 0; tv.tv_usec = 1000 * sb_mastertimeout.value; ret = select(newsocket+1, &fd, NULL, NULL, &tv); // get answer i = sizeof(hostaddr); if (ret > 0) ret = recvfrom (newsocket, (char *) answer, 10000, 0, (struct sockaddr *)&hostaddr, (socklen_t *)&i); if (ret > 0 && ret < 10000) { SockadrToNetadr (&hostaddr, &from); if (from.ip[0] == s->address.address.ip[0] && from.ip[1] == s->address.address.ip[1] && from.ip[2] == s->address.address.ip[2] && from.ip[3] == s->address.address.ip[3] && from.port == s->address.address.port) { answer[ret] = 0; if (memcmp(answer, "\xff\xff\xff\xff\x64\x0a", 6)) { continue; } // create servers avoiding duplicates for (i=6; i+5 < ret; i+=6) { char buf[32]; server_data* server; qbool exists = false; int j; snprintf(buf, sizeof (buf), "%u.%u.%u.%u:%u", (int)answer[i+0], (int)answer[i+1], (int)answer[i+2], (int)answer[i+3], 256 * (int)answer[i+4] + (int)answer[i+5]); server = Create_Server(buf); for (j=0; j<serversn; j++) { if (NET_CompareAdr(servers[j]->address, server->address)) { exists = true; break; } } if (!exists) servers[serversn++] = server; else Delete_Server(server); } } } } // copy all servers to source list if (serversn > 0) { updated++; SB_ServerList_Lock(); Reset_Source(s); s->servers = (server_data **) Q_malloc(serversn * sizeof(server_data *)); for (i=0; i < serversn; i++) s->servers[i] = servers[i]; s->serversn = serversn; s->servers_allocated = serversn; if (s->checked) rebuild_servers_list = 1; GetLocalTime(&(s->last_update)); SB_ServerList_Unlock(); if (sb_mastercache.value) DumpSource(s); } ping_pos = updated / (double)total_masters; } closesocket(newsocket); // Not having this here leads to crash almost always when some // other action with servers list happens right after this function. // Even 1 ms delay was enough during the tests, previously 500 ms was used. //Sys_MSleep(100); updating_sources = 0; sb_queuedtriggers |= SB_TRIGGER_SOURCESUPDATED; return 0; }
void Update_Source(source_data *s) { int i; qbool should_dump = false; server_data *servers[MAX_SERVERS]; int serversn = 0; if (s->type == type_dummy) return; if (s->type == type_file) { // read servers from file char name[1024]; snprintf(name, sizeof (name), "sb/%s", s->address.filename); should_dump = Update_Source_From_File(s, name, servers, &serversn); GetLocalTime(&(s->last_update)); } if (s->type == type_url) { SB_Update_Source_From_URL(s, servers, &serversn); } if (s->type == type_master) { // get servers from master server char request[] = {'c', '\n', '\0'}; socket_t newsocket; struct sockaddr_storage server; int ret = 0, i; unsigned char answer[10000]; fd_set fd; struct timeval tv; int trynum; int timeout; newsocket = UDP_OpenSocket(PORT_ANY); // so we have a socket // send status request for (trynum=0; trynum < sb_masterretries.value; trynum++) { NetadrToSockadr (&(s->address.address), &server); ret = sendto (newsocket, request, sizeof(request), 0, (struct sockaddr *)&server, sizeof(server) ); } if (ret < 0) return; timeout = Sys_DoubleTime() + (sb_mastertimeout.value / 1000.0); while (Sys_DoubleTime() < timeout) { //fd.fd_count = 1; //fd.fd_array[0] = newsocket; FD_ZERO(&fd); FD_SET(newsocket, &fd); tv.tv_sec = 0; tv.tv_usec = 1000 * 1.5 * sb_mastertimeout.value; // multiply timeout by 1.5 ret = select(newsocket+1, &fd, NULL, NULL, &tv); // get answer if (ret > 0) ret = recvfrom (newsocket, (char *) answer, 10000, 0, NULL, NULL); if (ret > 0 && ret < 10000) { answer[ret] = 0; if (memcmp(answer, "\xff\xff\xff\xff\x64\x0a", 6)) { closesocket(newsocket); return; } // create servers avoiding duplicates for (i=6; i+5 < ret; i+=6) { char buf[32]; server_data* server; qbool exists = false; int j; snprintf(buf, sizeof (buf), "%u.%u.%u.%u:%u", (int)answer[i+0], (int)answer[i+1], (int)answer[i+2], (int)answer[i+3], 256 * (int)answer[i+4] + (int)answer[i+5]); server = Create_Server(buf); for (j=0; j<serversn; j++) { if (NET_CompareAdr(servers[j]->address, server->address)) { exists = true; break; } } if (!exists) servers[serversn++] = server; else Delete_Server(server); } } } closesocket(newsocket); } SB_ServerList_Lock(); // copy all servers to source list if (serversn > 0) { Reset_Source(s); s->servers = (server_data **) Q_malloc((serversn + (s->type==type_file ? MAX_UNBOUND : 0)) * sizeof(server_data *)); for (i=0; i < serversn; i++) s->servers[i] = servers[i]; s->serversn = serversn; s->servers_allocated = serversn + (s->type == type_file ? MAX_UNBOUND : 0); if (s->checked) rebuild_servers_list = 1; if (sb_mastercache.value) { DumpSource(s); should_dump = false; } GetLocalTime(&(s->last_update)); } else if (s->type == type_file) { Reset_Source(s); s->servers = (server_data **) Q_malloc((serversn + (s->type==type_file ? MAX_UNBOUND : 0)) * sizeof(server_data *)); } SB_ServerList_Unlock(); if (should_dump) DumpSource(s); //Com_Printf ("Updating %15.15s: %d servers\n", s->name, serversn); }