void InitAsyncConnections(void) { WSADATA WSAData; if (WSAStartup(MAKEWORD(1,1),&WSAData) != 0) { eprintf("InitAsyncConnections can't open WinSock!\n"); return; } maintenance_buffer = (char *)malloc(strlen(ConfigStr(SOCKET_MAINTENANCE_MASK)) + 1); strcpy(maintenance_buffer,ConfigStr(SOCKET_MAINTENANCE_MASK)); // now parse out each maintenance ip maintenance_masks[num_maintenance_masks] = strtok(maintenance_buffer,";"); while (maintenance_masks[num_maintenance_masks] != NULL) { num_maintenance_masks++; if (num_maintenance_masks == MAX_MAINTENANCE_MASKS) break; maintenance_masks[num_maintenance_masks] = strtok(NULL,";"); } /* { int i; for (i=0;i<num_maintenance_masks;i++) { dprintf("mask %i is [%s]\n",i,maintenance_masks[i]); } } */ }
/* * LoadRsc: Loads the RESOURCE_RSC_SPEC files (.rsc or .rsb). */ void LoadRsc(void) { char file_load_path[MAX_PATH+FILENAME_MAX]; char *filespec = ConfigStr(RESOURCE_RSC_SPEC); char *filepath = ConfigStr(PATH_RSC); int files_loaded = 0; sprintf(file_load_path, "%s%s", filepath, filespec); StringVector files; if (FindMatchingFiles(file_load_path, &files)) { for (StringVector::iterator it = files.begin(); it != files.end(); ++it) { sprintf(file_load_path, "%s%s", filepath, it->c_str()); if (RscFileLoad(file_load_path, EachLoadRsc)) { if (stricmp(filespec, "*.rsb") == 0) LoadRSBHash(file_load_path); files_loaded++; } else eprintf("LoadRsc error loading %s\n", it->c_str()); } } dprintf("LoadRsc loaded %i of %i found %s files\n", files_loaded, files.size(), filespec); }
void LoadMotd(void) { char file_load_path[MAX_PATH+FILENAME_MAX]; char file_copy_path[MAX_PATH+FILENAME_MAX]; sprintf(file_load_path,"%s%s",ConfigStr(PATH_MOTD),MOTD_FILE); sprintf(file_copy_path,"%s%s",ConfigStr(PATH_MEMMAP),MOTD_FILE); /* if there's a new motd file, move it in */ if (access(file_load_path,0) != -1) if (!MoveFileEx(file_load_path,file_copy_path,MOVEFILE_REPLACE_EXISTING)) eprintf("LoadMotd can't move %s\n",MOTD_FILE); /* else dprintf("LoadMotd moved in the new message of the day\n"); */ LoadMotdName(file_copy_path); /* if (motd != NULL) dprintf("LoadMotd loaded the message of the day\n"); else dprintf("LoadMotd found no message of the day\n"); */ }
void SaveControlFile(int save_time) { char save_name[MAX_PATH+FILENAME_MAX]; FILE *savefile; sprintf(save_name,"%s%s",ConfigStr(PATH_LOADSAVE),SAVE_CONTROL_FILE); if ((savefile = fopen(save_name,"wt")) == NULL) { eprintf("SaveContrtolFile can't open %s to save date/time of successful save!!!\n", save_name); return; } fprintf(savefile,"#\n"); fprintf(savefile,"# Control file for last successful save\n"); fprintf(savefile,"#\n"); fprintf(savefile,"# Files written:\n"); fprintf(savefile,"# %s%s%i\n",ConfigStr(PATH_LOADSAVE),GAME_FILE_SAVE,save_time); fprintf(savefile,"# %s%s%i\n",ConfigStr(PATH_LOADSAVE),ACCOUNT_FILE_SAVE,save_time); fprintf(savefile,"# %s%s%i\n",ConfigStr(PATH_LOADSAVE),STRING_FILE_SAVE,save_time); fprintf(savefile,"# %s%s%i\n",ConfigStr(PATH_LOADSAVE),DYNAMIC_RSC_FILE_SAVE,save_time); fprintf(savefile,"#\n"); fprintf(savefile,"# Last successful save was at %s\n",TimeStr(save_time)); fprintf(savefile,"#\n"); fprintf(savefile,"\n"); fprintf(savefile,"LASTSAVE %i\n",save_time); fclose(savefile); }
void LoadBof(void) { HANDLE hFindFile; WIN32_FIND_DATA search_data; int files_found; int files_loaded; char file_load_path[MAX_PATH+FILENAME_MAX]; char file_copy_path[MAX_PATH+FILENAME_MAX]; files_found = 0; files_loaded = 0; sprintf(file_load_path,"%s%s",ConfigStr(PATH_BOF),BOF_SPEC); hFindFile = FindFirstFile(file_load_path,&search_data); if (hFindFile != INVALID_HANDLE_VALUE) { do { files_found++; sprintf(file_load_path,"%s%s",ConfigStr(PATH_BOF),search_data.cFileName); sprintf(file_copy_path,"%s%s",ConfigStr(PATH_MEMMAP),search_data.cFileName); if (BlakMoveFile(file_load_path,file_copy_path)) files_loaded++; } while (FindNextFile(hFindFile,&search_data)); FindClose(hFindFile); } /* if (files_found > 0) dprintf("LoadBof moved in %i of %i found new .bof files\n",files_loaded,files_found); */ //dprintf("starting to load bof files\n"); files_found = 0; files_loaded = 0; sprintf(file_load_path,"%s%s",ConfigStr(PATH_MEMMAP),BOF_SPEC); hFindFile = FindFirstFile(file_load_path,&search_data); if (hFindFile != INVALID_HANDLE_VALUE) { do { files_found++; sprintf(file_load_path,"%s%s",ConfigStr(PATH_MEMMAP),search_data.cFileName); if (LoadBofName(file_load_path)) files_loaded++; else eprintf("LoadAllBofs can't load %s\n",search_data.cFileName); } while (FindNextFile(hFindFile,&search_data)); FindClose(hFindFile); } SetClassesSuperPtr(); SetClassVariables(); SetMessagesPropagate(); //dprintf("LoadBof loaded %i of %i found .bof files\n",files_loaded,files_found); }
int SaveAll(void) { Bool save_ok; int save_time; char save_name[MAX_PATH+FILENAME_MAX]; char time_str[100]; /* Note: You must call GarbageCollect() right before SaveAll() */ /* charlie: machine sets the local time from a time synch server its potentially dangerous, but only if the time has been changed between either server startup or last save, which is unlikely to have drifted by much, things will only start to freak out if the difference is more than say a minute behind, meaning the all the timers will run for an extra minute.. its better this way as the time is going to be corrected every (currently) 4 hours , even the worst PC clocks aren`t going to degrade that much in 4 hours */ /* The current time is used as a suffix to the save filenames. We make our own copy since the time functions use a static buffer. */ save_time = GetTime(); sprintf(time_str,"%i",save_time); save_ok = True; lprintf("Saving game (time stamp %s)...\n", time_str); sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),GAME_FILE_SAVE,time_str); if (SaveGame(save_name) == False) save_ok = False; sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),STRING_FILE_SAVE,time_str); if (SaveStrings(save_name) == False) save_ok = False; sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),ACCOUNT_FILE_SAVE,time_str); if (SaveAccounts(save_name) == False) save_ok = False; sprintf(save_name,"%s%s%s",ConfigStr(PATH_LOADSAVE),DYNAMIC_RSC_FILE_SAVE,time_str); if (!SaveDynamicRsc(save_name)) save_ok = False; if (save_ok) SaveControlFile(save_time); lprintf("Save game successful (time stamp %s).\n", time_str); if (save_ok) return save_time; return 0; }
void LoadAdminConstants(void) { FILE *constantsfile; char line[MAX_CONSTANTS_LINE]; int lineno; char *name_str, *value_str; int value; if (ConfigBool(CONSTANTS_ENABLED) == False) return; if ((constantsfile = fopen(ConfigStr(CONSTANTS_FILENAME), "rt")) == NULL) { eprintf("LoadAdminConstants can't open %s, no constants\n", ConfigStr(CONSTANTS_FILENAME)); return; } lineno = 0; while (fgets(line, MAX_CONSTANTS_LINE, constantsfile)) { lineno++; name_str = strtok(line, "= \t\n"); /* ignore blank lines */ if (name_str == NULL) continue; /* ignore comments lines */ if (strlen(name_str) > 1 && name_str[0] == '/' && name_str[1] == '/') continue; value_str = strtok(NULL, "= \t\n"); if (name_str == NULL || name_str[0] == '/') { eprintf("LoadAdminConstants error reading value on line %i\n", lineno); continue; } if (sscanf(value_str, "%i", &value) != 1) { eprintf("LoadAdminConstants error parsing integer on line %i\n", lineno); continue; } AddAdminConstant(name_str, value); } fclose(constantsfile); }
void LoadBof(void) { char file_load_path[MAX_PATH+FILENAME_MAX]; char file_copy_path[MAX_PATH+FILENAME_MAX]; int files_loaded = 0; sprintf(file_load_path,"%s%s",ConfigStr(PATH_BOF),BOF_SPEC); StringVector files; if (FindMatchingFiles(file_load_path, &files)) { for (StringVector::iterator it = files.begin(); it != files.end(); ++it) { sprintf(file_load_path,"%s%s",ConfigStr(PATH_BOF), it->c_str()); sprintf(file_copy_path,"%s%s",ConfigStr(PATH_MEMMAP), it->c_str()); if (BlakMoveFile(file_load_path,file_copy_path)) files_loaded++; } } /* if (!files.empty()) dprintf("LoadBof moved in %i of %i found new .bof files\n",files_loaded,files.size()); */ //dprintf("starting to load bof files\n"); files_loaded = 0; sprintf(file_load_path,"%s%s",ConfigStr(PATH_MEMMAP),BOF_SPEC); if (FindMatchingFiles(file_load_path, &files)) { for (StringVector::iterator it = files.begin(); it != files.end(); ++it) { sprintf(file_load_path,"%s%s",ConfigStr(PATH_MEMMAP), it->c_str()); if (LoadBofName(file_load_path)) files_loaded++; else eprintf("LoadAllBofs can't load %s\n", it->c_str()); } } SetClassesSuperPtr(); SetClassVariables(); SetMessagesPropagate(); dprintf("LoadBof loaded %i of %i found .bof files\n",files_loaded,files.size()); }
void SetMotd(char *new_motd) { int fh; char filename[MAX_PATH+FILENAME_MAX]; /* write file to memmap directory */ sprintf(filename,"%s%s",ConfigStr(PATH_MEMMAP),MOTD_FILE); fh = open(filename,O_CREAT | O_TRUNC | O_BINARY | O_WRONLY,S_IREAD | S_IWRITE); if (fh == -1) { eprintf("SetMotd error saving motd file to %s\n",filename); return; } if (write(fh,new_motd,strlen(new_motd)) != (int)strlen(new_motd)) { eprintf("SetMotd error writing motd file to %s\n",filename); close(fh); return; } close(fh); ResetLoadMotd(); LoadMotdName(filename); }
char * GetMotd(void) { if (motd != NULL) return motd; else return ConfigStr(MOTD_DEFAULT); }
int GetMotdLength(void) { if (motd != NULL) return strlen(motd); else return strlen(ConfigStr(MOTD_DEFAULT)); }
void AddBuiltInDLlist() { char filename[MAX_PATH+FILENAME_MAX]; FILE *packagefile; char line[MAX_PACKAGE_LINE+1]; int lineno,time,type,size; char *t1,*t2,*t3,*t4; sprintf(filename,"%s%s",ConfigStr(PATH_PACKAGE_FILE),PACKAGE_FILE); if ((packagefile = fopen(filename,"rt")) == NULL) { eprintf("AddBuiltinDLlist can't open %s to load the packages!\n", filename); return; } lineno = 0; while (fgets(line,MAX_PACKAGE_LINE,packagefile)) { lineno++; t1 = strtok(line," \t\n"); if (t1 == NULL) /* ignore blank lines */ continue; if (*t1 == '#') /* ignore commentns */ continue; t2 = strtok(NULL," \t\n"); if (t2 == NULL || sscanf(t2,"%i",&time) != 1) { eprintf("AddBuiltInDLlist (%i) can't read time\n",lineno); continue; } t3 = strtok(NULL," \t\n"); if (t3 == NULL || sscanf(t3,"%i",&type) != 1) { eprintf("AddBuiltInDLlist (%i) can't read type\n",lineno); continue; } t4 = strtok(NULL," \t\n"); if (t4 == NULL || sscanf(t4,"%i",&size) != 1) { size = 1024; // default file size #if 0 eprintf("AddBuiltInDLlist (%i) can't read size\n",lineno); continue; #endif } AddOrUpdateDLlist(t1,time,type,size); } fclose(packagefile); }
void CreateAccountFromSMTPMail(smtp_node *smtp) { #ifdef SMTP_TEST return; #else int len_buf; char *buf; string_list *sl; /* put mail into buffer, than analyze, then free buffer */ len_buf = 0; sl = smtp->data; while (sl != NULL) { len_buf += strlen(sl->str); sl = sl->next; } buf = (char *) AllocateMemory(MALLOC_ID_SMTP,len_buf+1); len_buf = 0; sl = smtp->data; while (sl != NULL) { strcpy(buf+len_buf,sl->str); len_buf += strlen(sl->str); sl = sl->next; } if (strcmp(smtp->forward_path->str,ConfigStr(EMAIL_ACCOUNT_CREATE_NAME)) == 0) { CreateAccountFromBuffer(buf); } else { if (strcmp(smtp->forward_path->str,ConfigStr(EMAIL_ACCOUNT_DELETE_NAME)) == 0) DeleteAccountFromBuffer(buf); } FreeMemory(MALLOC_ID_SMTP,buf,len_buf+1); #endif }
FILE *CreateFileChannel(int channel_id) { char channel_file[MAX_PATH+FILENAME_MAX]; FILE *pFile; sprintf(channel_file,"%s%s",ConfigStr(PATH_CHANNEL),channel_table[channel_id].file_name); pFile = fopen(channel_file, "ab"); return pFile; }
Bool ExistInternetMailName(char *s) { #ifdef SMTP_TEST return True; #else val_type ret_val; return (strcmp(s,ConfigStr(EMAIL_ACCOUNT_CREATE_NAME)) == 0) || (strcmp(s,ConfigStr(EMAIL_ACCOUNT_DELETE_NAME)) == 0); /* only account creation right now */ EnterServerLock(); ret_val.int_val = GetInternetMailObject(s); LeaveServerLock(); return (ret_val.v.tag == TAG_OBJECT); #endif }
void PageAlert(char *subject,char *message) { char messagebuf[4000]; char FAR hostname[256]; unsigned int i; int res; char *mailServer; char *emailAddress; /* hostname of computer */ gethostname((char *)&hostname ,255-1); mailServer = ConfigStr( EMAIL_HOST ); emailAddress = ConfigStr( EMAIL_NAME ); /* don`t want spaces in either subject or message */ for(i=0;i<strlen( subject ); i++) { if(subject[ i ] == ' ' ) subject[ i ] = '_'; } for(i=0;i<strlen( message ); i++) { if(message[ i ] == ' ' ) message[ i ] = '_'; } /* build the command string , bypass the mail filter .. (its ok we`re inside 3do) */ /* until i finish the internal mail sender, i`ve ignored the subject parameter */ sprintf(messagebuf,"mailto -H %s -U %s -S Warning -M %s -D %s",mailServer,hostname,message,emailAddress); dprintf(messagebuf); /* calling system() requires a flush of all buffered streams */ _flushall(); /* handle any returns from system */ res = system(messagebuf); /* handle any returns from system */ if(res==-1) { DisplayErrnoText(); } else dprintf("system command returned %d\n",res); }
void LoadRsc(void) { char file_load_path[MAX_PATH+FILENAME_MAX]; int files_loaded = 0; StringVector files; if (FindMatchingFiles(ConfigStr(PATH_RSC), RSC_EXTENSION, &files)) { for (StringVector::iterator it = files.begin(); it != files.end(); ++it) { sprintf(file_load_path,"%s%s",ConfigStr(PATH_RSC), it->c_str()); if (RscFileLoad(file_load_path,EachLoadRsc)) files_loaded++; else eprintf("LoadRsc error loading %s\n", it->c_str()); } } /* dprintf("LoadRsc loaded %i of %i found .rsc files\n",files_loaded,files.size()); */ }
void MySQLInit() { if (ConfigBool(MYSQL_ENABLED) == False) return; enabled = true; mysqlcon = mysql_init(NULL); if (mysqlcon == NULL) { dprintf("%s\n", mysql_error(mysqlcon)); return; } if (mysql_real_connect(mysqlcon, ConfigStr(MYSQL_HOST), ConfigStr(MYSQL_USERNAME), ConfigStr(MYSQL_PASSWORD), NULL, 0, NULL, 0) == NULL) { dprintf("Error connecting: %s\n", mysql_error(mysqlcon)); dprintf("host: %s user: %s pass: %s", ConfigStr(MYSQL_HOST), ConfigStr(MYSQL_USERNAME), ConfigStr(MYSQL_PASSWORD)); mysql_close(mysqlcon); return; } else { dprintf("connected to mysql host: %s user: %s", ConfigStr(MYSQL_HOST),ConfigStr(MYSQL_USERNAME) ); } //Check for valid schema here... char buf[100]; sprintf(buf, "USE %s", ConfigStr(MYSQL_DB)); if(mysql_query(mysqlcon, buf)) { dprintf("Error selecting databsae: %s\n", mysql_error(mysqlcon)); return; } else { dprintf("connected to mysql database: %s", ConfigStr(MYSQL_DB)); } connected = true; return; }
void InitAccount(void) { accounts = NULL; next_account_id = 1; console_account = &console_account_node; console_account->account_id = 0; console_account->name = ConfigStr(CONSOLE_ADMINISTRATOR); console_account->password = (char *)AllocateMemory(MALLOC_ID_ACCOUNT,1); console_account->password[0] = 0; console_account->type = ACCOUNT_ADMIN; console_account->last_login_time = 0; console_account->suspend_time = 0; console_account->credits = 0; }
account_node * AccountLoginByName(char *name) { account_node *a; if (0 == stricmp(name,ConfigStr(GUEST_ACCOUNT))) { if (GetUsedGuestAccounts() >= ConfigInt(GUEST_MAX)) return NULL; a = accounts; while (a != NULL) { if (a->type == ACCOUNT_GUEST) { if (GetSessionByAccount(a) == NULL) { /* no one using this particular guest account, so we will */ /* give guests credits every time they login */ /* a->credits = 100*ConfigInt(GUEST_CREDITS); */ return a; } } a = a->next; } } else { a = accounts; while (a != NULL) { if (!stricmp(a->name,name)) { /* give administrators credits every time they login */ /* if (a->type == ACCOUNT_ADMIN) a->credits = 100*ConfigInt(CREDIT_ADMIN); */ return a; } a = a->next; } } return NULL; }
int LoadRoom(int resource_id) { val_type ret_val; resource_node* r; room_rsc_node *rrsc; char s[MAX_PATH + FILENAME_MAX]; /****************************************************************/ r = GetResourceByID(resource_id); if (!r) { bprintf("LoadRoomData can't find resource %i\n",resource_id); return NIL; } ret_val.v.tag = TAG_ROOM_DATA; /****************************************************************/ // CASE 1: Reuse already loaded ROO if (room_rscs) { rrsc = room_rscs[resource_id % INIT_ROOMTABLE_SIZE]; while (rrsc) { if (rrsc->resource_id == resource_id) { ret_val.v.data = rrsc->roomdata_id; return ret_val.int_val; } rrsc = rrsc->next; } } /****************************************************************/ // CASE 2: Load ROO room_node* newnode = (room_node*)AllocateMemory(MALLOC_ID_ROOM, sizeof(room_node)); // combine path for roo and filename sprintf(s, "%s%s", ConfigStr(PATH_ROOMS), r->resource_val[0]); // try load it if (!BSPLoadRoom(s, &newnode->data)) { FreeMemory(MALLOC_ID_ROOM, newnode, sizeof(room_node)); bprintf("LoadRoomData couldn't open %s!!!\n",r->resource_val[0]); return NIL; } // Add this room_node to the rooms table. newnode->data.roomdata_id = idcounter++; newnode->data.resource_id = resource_id; newnode->next = rooms[newnode->data.roomdata_id % INIT_ROOMTABLE_SIZE]; rooms[newnode->data.roomdata_id % INIT_ROOMTABLE_SIZE] = newnode; // Add room_rsc_node for this resource. rrsc = (room_rsc_node *)AllocateMemory(MALLOC_ID_ROOM, sizeof(room_rsc_node)); rrsc->resource_id = resource_id; rrsc->roomdata_id = newnode->data.roomdata_id; rrsc->next = room_rscs[resource_id % INIT_ROOMTABLE_SIZE]; room_rscs[resource_id % INIT_ROOMTABLE_SIZE] = rrsc; ret_val.v.data = newnode->data.roomdata_id; return ret_val.int_val; }
void ServiceTimers(void) { MSG msg; INT64 ms; StartupComplete(); /* for the interface to report no errors on startup */ InterfaceUpdate(); lprintf("Status: %i accounts\n",GetNextAccountID()); lprintf("-------------------------------------------------------------------------------------\n"); dprintf("-------------------------------------------------------------------------------------\n"); eprintf("-------------------------------------------------------------------------------------\n"); in_main_loop = True; SetWindowText(hwndMain, ConfigStr(CONSOLE_CAPTION)); AsyncSocketStart(); for(;;) { if (timers == NULL) ms = 500; else { ms = timers->time - GetMilliCount(); if (ms <= 0) ms = 0; if (ms > 500) ms = 500; } if (MsgWaitForMultipleObjects(0,NULL,0,(DWORD)ms,QS_ALLINPUT) == WAIT_OBJECT_0) { while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message == WM_QUIT) { lprintf("ServiceTimers shutting down the server\n"); return; } switch (msg.message) { case WM_BLAK_MAIN_READ : EnterServerLock(); PollSession(msg.lParam); TimerActivate(); LeaveServerLock(); break; case WM_BLAK_MAIN_RECALIBRATE : /* new soonest timer, so we should recalculate our time left... so we just need to restart the loop! */ break; case WM_BLAK_MAIN_DELETE_ACCOUNT : EnterServerLock(); DeleteAccountAndAssociatedUsersByID(msg.lParam); LeaveServerLock(); break; case WM_BLAK_MAIN_VERIFIED_LOGIN : EnterServerLock(); VerifiedLoginSession(msg.lParam); LeaveServerLock(); break; case WM_BLAK_MAIN_LOAD_GAME : EnterServerLock(); LoadFromKod(msg.lParam); LeaveServerLock(); break; default : dprintf("ServiceTimers got unknown message %i\n",msg.message); break; } } } else { /* a Blakod timer is ready to go */ EnterServerLock(); PollSessions(); /* really just need to check session timers */ TimerActivate(); LeaveServerLock(); } } }