const char *GetMODVersion(void) { static msg_t msg; // we must be connected to the master server before writing to it if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) { CONS_Printf("cannot connect to the master server\n"); M_StartMessage("There was a problem connecting to\nthe Master Server", NULL, MM_NOTHING); return NULL; } msg.type = GET_VERSION_MSG; msg.length = sizeof MODVERSION; msg.room = MODID; // Might as well use it for something. sprintf(msg.buffer,"%d",MODVERSION); if (MS_Write(&msg) < 0) return NULL; MS_Read(&msg); CloseConnection(); if(strcmp(msg.buffer,"NULL") != 0) { return msg.buffer; } else return NULL; }
/** Gets a list of game servers from the master server. */ static INT32 GetServersList(void) { msg_t msg; INT32 count = 0; msg.type = GET_SERVER_MSG; msg.length = 0; msg.room = 0; if (MS_Write(&msg) < 0) return MS_WRITE_ERROR; while (MS_Read(&msg) >= 0) { if (!msg.length) { if (!count) CONS_Printf("No servers currently running.\n"); return MS_NO_ERROR; } count++; CONS_Printf("%s",msg.buffer); } return MS_READ_ERROR; }
const msg_server_t *GetShortServersList(INT32 room) { static msg_server_t server_list[NUM_LIST_SERVER+1]; // +1 for easy test msg_t msg; INT32 i; // updated now oldroomnum = room; // we must be connected to the master server before writing to it if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) { CONS_Printf("cannot connect to the master server\n"); M_StartMessage("There was a problem connecting to\nthe Master Server", NULL, MM_NOTHING); return NULL; } msg.type = GET_SHORT_SERVER_MSG; msg.length = 0; msg.room = room; if (MS_Write(&msg) < 0) return NULL; for (i = 0; i < NUM_LIST_SERVER && MS_Read(&msg) >= 0; i++) { if (!msg.length) { server_list[i].header.buffer[0] = 0; CloseConnection(); return server_list; } M_Memcpy(&server_list[i], msg.buffer, sizeof (msg_server_t)); server_list[i].header.buffer[0] = 1; } CloseConnection(); if (i == NUM_LIST_SERVER) { server_list[i].header.buffer[0] = 0; return server_list; } else return NULL; }
/* * read big endian value from memory stream */ long long MS_ReadBE(Memstream* memstream, int size) { unsigned char* data; /* raw data */ int i; /* loop variable */ long long ret; /* return value */ /* allocate data for raw memory */ data = (unsigned char*)malloc(size); ret = 0; /* read raw memory (converting directly from memory would be faster) */ MS_Read(memstream, data, size); /* convert to long long */ for (i = 0; i < size; i++) { ret = ret<<8; ret += data[i]; } /* cleanup */ free(data); /* return */ return ret; }
/** Gets a list of game servers from the master server. */ static inline int GetServersList(SOCKET socket) { msg_t msg; int count = 0; msg.type = GET_SERVER_MSG; msg.length = 0; if (MS_Write(&msg, socket) < 0) return MS_WRITE_ERROR; while (MS_Read(&msg, socket) >= 0) { if (!msg.length) { // if (!count) // printf("No server currently running.\n"); return MS_NO_ERROR; } count++; printf(msg.buffer); } return MS_READ_ERROR; }
/** Get the MOTD from the master server. */ static inline INT32 GetMSMOTD(void) { msg_t msg; INT32 count = 0; msg.type = GET_MOTD_MSG; msg.length = 0; if (MS_Write(&msg) < 0) return MS_WRITE_ERROR; while (MS_Read(&msg) >= 0) { if (!msg.length) { if (!count) CONS_Printf("%s", M_GetText("No servers currently running.\n")); return MS_NO_ERROR; } count++; CONS_Printf("%s",msg.buffer); } return MS_READ_ERROR; }
INT32 GetRoomsList(boolean hosting) { static msg_ban_t banned_info[1]; msg_t msg; INT32 i; // we must be connected to the master server before writing to it if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) { CONS_Printf("cannot connect to the master server\n"); M_StartMessage("There was a problem connecting to\nthe Master Server", NULL, MM_NOTHING); return -1; } if (hosting) msg.type = GET_ROOMS_HOST_MSG; else msg.type = GET_ROOMS_MSG; msg.length = 0; msg.room = 0; if (MS_Write(&msg) < 0) { room_list[0].id = 1; strcpy(room_list[0].motd,"Master Server Offline."); strcpy(room_list[0].name,"Offline"); return -1; } for (i = 0; i < NUM_LIST_ROOMS && MS_Read(&msg) >= 0; i++) { if(msg.type == GET_BANNED_MSG) { char banmsg[1000]; M_Memcpy(&banned_info[0], msg.buffer, sizeof (msg_ban_t)); if (hosting) sprintf(banmsg, "You have been banned from\nhosting netgames.\n\nUnder the following IP Range:\n%s - %s\n\nFor the following reason:\n%s\n\nYour ban will expire on:\n%s",banned_info[0].ipstart,banned_info[0].ipend,banned_info[0].reason,banned_info[0].endstamp); else sprintf(banmsg, "You have been banned from\njoining netgames.\n\nUnder the following IP Range:\n%s - %s\n\nFor the following reason:\n%s\n\nYour ban will expire on:\n%s",banned_info[0].ipstart,banned_info[0].ipend,banned_info[0].reason,banned_info[0].endstamp); M_StartMessage(banmsg, NULL, MM_NOTHING); cv_internetserver.value = false; return -2; } if (!msg.length) { room_list[i].header.buffer[0] = 0; CloseConnection(); return 1; } M_Memcpy(&room_list[i], msg.buffer, sizeof (msg_rooms_t)); room_list[i].header.buffer[0] = 1; } CloseConnection(); if (i == NUM_LIST_ROOMS) { room_list[i].header.buffer[0] = 0; return 1; } else { room_list[0].id = 1; strcpy(room_list[0].motd,"Master Server Offline."); strcpy(room_list[0].name,"Offline"); return -1; } }