source: Daodan/src/Flatline_Server.c@ 568

Last change on this file since 568 was 484, checked in by gumby, 15 years ago

ZOMG FLATLINE

File size: 2.2 KB
RevLine 
[484]1#include "Flatline.h"
2#include "Flatline_Server.h"
3
4int total_players = 0;
5uint16_t max_connections = MAX_CONNECTIONS;
6
7player_info* FLrServer_AddPlayer(int ip, char* name, bool is_server) {
8 uint32_t player_slot = 0;
9 int playerlist_slot = 0;
10 if(is_server) goto server;
11 if(total_players < max_connections) {
12 playerlist_slot = FLr_FindEmptyListSlot();
13 total_players++;
14
15 //send new player packet to all players
16 //char tempname[32] = {0};
17 int i = 0;
18 int k = 0;
19 //checks to see if a name exists or not
20 //then appends [#] on the end of it if it does
21 char* zero = strchr(name, 0);
22 if(zero - name > 28) zero = name + 28;
23 for(i = 0; i < max_connections; i++) {
24 if(PlayerList[i] != 0 && strcmp(name, PlayerList[i]->name)) {
25 k++;
26 sprintf(zero, "[%i]", k);
27 i = 0;
28 }
29 }
30
31server: ;flatline_packet new_char = {0};
32 CharacterObject* Char = &(((new_player*)(new_char.data))->Character);
33 memset(Char, 0, sizeof(CharacterObject));
34 Char->Header.Type = 'CHAR';
35 //Char->OSD.Options = char_dontaim;
36 sprintf(Char->OSD.Name,"%s",name);
37 sprintf(Char->OSD.Class, "%s", "striker_easy_1");
38
39
40
41 //TMrInstance_GetDataPtr('ONCC', "striker_easy_1", PlayerList[playerlist_slot]->Chr->ONCC);
42
43
44 new_char.id = NEW_PLAYER;
45 if(!is_server) {
46 ONrGameState_NewCharacter(Char, NULL, NULL, &(player_slot));
47 PlayerList[playerlist_slot] = Players+player_slot;
48 PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot];
49 PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF;
50 sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name);
51 UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
52
53 }
54 else {
55 PlayerList[0] = Players;
56 PlayerList[0]->Chr = (Character *)(((GameState * )(ONgGameState))->CharacterStorage);
57 }
58
59 //add player to list
60
61 PlayerList[playerlist_slot]->ip = ip;
62 PlayerList[playerlist_slot]->list_slot = playerlist_slot;
63 sprintf(PlayerList[playerlist_slot]->name,"%.31s",name);
64
65 return &Players[player_slot];
66 }
67 return (player_info*)-1;
68}
69
70void FLrServer_Initialize(){
71 FLrServer_AddPlayer(inet_addr("127.0.0.1"), "host", 1);
72
73
74}
Note: See TracBrowser for help on using the repository browser.