#include "Flatline.h" #include "Flatline_Server.h" int total_players = 0; uint16_t max_connections = MAX_CONNECTIONS; player_info* FLrServer_AddPlayer(int ip, char* name, bool is_server) { uint32_t player_slot = 0; int playerlist_slot = 0; if(is_server) goto server; if(total_players < max_connections) { playerlist_slot = FLr_FindEmptyListSlot(); total_players++; //send new player packet to all players //char tempname[32] = {0}; int i = 0; int k = 0; //checks to see if a name exists or not //then appends [#] on the end of it if it does char* zero = strchr(name, 0); if(zero - name > 28) zero = name + 28; for(i = 0; i < max_connections; i++) { if(PlayerList[i] != 0 && strcmp(name, PlayerList[i]->name)) { k++; sprintf(zero, "[%i]", k); i = 0; } } server: ;flatline_packet new_char = {0}; CharacterObject* Char = &(((new_player*)(new_char.data))->Character); memset(Char, 0, sizeof(CharacterObject)); Char->Header.Type = 'CHAR'; //Char->OSD.Options = char_dontaim; sprintf(Char->OSD.Name,"%s",name); sprintf(Char->OSD.Class, "%s", "striker_easy_1"); //TMrInstance_GetDataPtr('ONCC', "striker_easy_1", PlayerList[playerlist_slot]->Chr->ONCC); new_char.id = NEW_PLAYER; if(!is_server) { ONrGameState_NewCharacter(Char, NULL, NULL, &(player_slot)); PlayerList[playerlist_slot] = Players+player_slot; PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot]; PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name); UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER ); } else { PlayerList[0] = Players; PlayerList[0]->Chr = (Character *)(((GameState * )(ONgGameState))->CharacterStorage); } //add player to list PlayerList[playerlist_slot]->ip = ip; PlayerList[playerlist_slot]->list_slot = playerlist_slot; sprintf(PlayerList[playerlist_slot]->name,"%.31s",name); return &Players[player_slot]; } return (player_info*)-1; } void FLrServer_Initialize(){ FLrServer_AddPlayer(inet_addr("127.0.0.1"), "host", 1); }