source: Daodan/MSVC/Flatline_Server.c@ 572

Last change on this file since 572 was 568, checked in by gumby, 14 years ago

Updates

File size: 3.4 KB
RevLine 
[567]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 flatline_packet new_char = {0};
9 CharacterObject* Char;
10 uint32_t player_slot = 0;
11 int playerlist_slot = 0;
12 if(is_server) goto server;
13 if(total_players < max_connections) {
14 char* zero = strchr(name, 0);
15 int i = 0;
16 int k = 0;
17 playerlist_slot = FLr_FindEmptyListSlot();
18
19
20 total_players++;
21
22 //send new player packet to all players
23 //char tempname[32] = {0};
24
25 //checks to see if a name exists or not
26 //then appends [#] on the end of it if it does
27
28 if(zero - name > 28) zero = name + 28;
29 for(i = 0; i < max_connections; i++) {
30 if(PlayerList[i] != 0 && !strcmp(name, PlayerList[i]->name)) {
31 k++;
32 sprintf(zero, "[%i]", k);
33 i = 0;
34 }
35 }
36
37server: ;
38 //memset( new_char, 0, sizeof(new_char);
39 //new_char = {0};
40 Char = &new_char.new_player.Character;
41 memset(Char, 0, sizeof(CharacterObject));
42 Char->Header.Type = 'CHAR';
43 //Char->OSD.Options = char_dontaim;
44 sprintf(Char->OSD.Name,"%s",name);
45 sprintf(Char->OSD.Class, "%s", "konoko_generic");
46
47
48
49 //TMrInstance_GetDataPtr('ONCC', "striker_easy_1", PlayerList[playerlist_slot]->Chr->ONCC);
50
51
52 new_char.id = NEW_PLAYER;
53 if(!is_server) {
54 ONrGameState_NewCharacter(Char, NULL, NULL, &(player_slot));
[568]55 //move this to a set up characters function...
56 ONgGameState->CharacterStorage[player_slot].field_1E8 = 0;
57
[567]58 PlayerList[playerlist_slot] = Players+player_slot;
[568]59 PlayerList[playerlist_slot]->spawnnumber = player_slot;
[567]60 PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot];
[568]61// PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
62 PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF
[567]63 sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name);
64 UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
65
66 }
67 else {
68 PlayerList[0] = Players;
69 PlayerList[0]->Chr = (Character *)(((GameState * )(ONgGameState))->CharacterStorage);
70 }
71
72 //add player to list
73
74 PlayerList[playerlist_slot]->ip = ip;
75 PlayerList[playerlist_slot]->list_slot = playerlist_slot;
76 sprintf(PlayerList[playerlist_slot]->name,"%.31s",name);
77
78 return &Players[player_slot];
79 }
80 return (player_info*)(-1);
81}
82
83void FLrServer_Initialize(){
84 FLrServer_AddPlayer(inet_addr("127.0.0.1"), "host", 1);
[568]85}
[567]86
[568]87//UDPServer_SendToAll
88//Sends a packet to all the clients currently connected.
89//Returns the number of players sent to.
90int UDPServer_SendToAll(void* packet, int size) {
91 int j;
92 int players = 0;
93 sockaddr_in address;
94 memset(&address, 0, sizeof(sockaddr_in));
95 address.sin_family = AF_INET;
96 address.sin_addr.s_addr = htonl(INADDR_ANY);
97 address.sin_port = htons(27777);
98 for(j = 0; j < max_connections; j++) {
99 if (PlayerList[j] != 0 && PlayerList[j]->ip && (PlayerList[j]->ip != inet_addr("127.0.0.1"))) {
100 int sent_bytes;
101 address.sin_addr.s_addr = htonl(PlayerList[j]->ip);//*((struct in_addr*)(int*)&(Players[j].ip));
102 sent_bytes = NetUDPServer_Send((sockaddr *) &address, (char*)packet, size);
103 if(sent_bytes == SOCKET_ERROR) NetCatchError();
104 else players++;
105 }
106 }
107 return players;
[567]108}
Note: See TracBrowser for help on using the repository browser.