1 | #include <winsock2.h> |
---|
2 | #include "BFW_ScriptLang.h" |
---|
3 | |
---|
4 | #include "Daodan_Patch.h" |
---|
5 | #include "Daodan_BSL.h" |
---|
6 | #include "Flatline_BSL.h" |
---|
7 | #include "Flatline.h" |
---|
8 | #include "Flatline_Server.h" |
---|
9 | #include "Mariusnet_Public.h" |
---|
10 | bool server_started = 0; |
---|
11 | bool client_connected = 0; |
---|
12 | int sock = 0; |
---|
13 | sockaddr_in address; |
---|
14 | char player_name[32] = "Striker"; |
---|
15 | char player_country[256] = {0}; |
---|
16 | int update_rate = 5; |
---|
17 | #include "Oni.h" |
---|
18 | #include "Daodan_Cheater.h" |
---|
19 | uint16_t ONICALL start_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
20 | { |
---|
21 | CreateThread(NULL, 0, StartServer, NULL, 0, 0); |
---|
22 | server_started = 1; |
---|
23 | return 0; |
---|
24 | } |
---|
25 | |
---|
26 | uint16_t ONICALL control_update_rate(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
27 | { |
---|
28 | update_rate = args[0].value_int32; |
---|
29 | server_started = 1; |
---|
30 | return 0; |
---|
31 | } |
---|
32 | |
---|
33 | uint16_t ONICALL change_name(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
34 | { |
---|
35 | |
---|
36 | //should also return your name... |
---|
37 | sprintf(player_name, "%.31s", args[0].value_str32); |
---|
38 | if(client_connected) { |
---|
39 | flatline_packet packet; |
---|
40 | packet.id = CHANGE_NAME; |
---|
41 | memcpy(packet.data, args[0].value_str32, 256); |
---|
42 | NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&packet, 257); |
---|
43 | } |
---|
44 | if(server_started) |
---|
45 | { |
---|
46 | FLsUpdateName( 0, args[0].value_str32 ); |
---|
47 | } |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|
51 | uint16_t ONICALL send_message(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
52 | { |
---|
53 | |
---|
54 | flatline_packet message; |
---|
55 | message.id = MESSAGE; |
---|
56 | |
---|
57 | if(server_started) { |
---|
58 | int message_size = sprintf(message.data, "%s: %s", player_name, args[0].value_str32); |
---|
59 | COrMessage_Print(message.data, "chat", 0); |
---|
60 | UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER ); |
---|
61 | } |
---|
62 | else if(client_connected) { |
---|
63 | sprintf(message.data, "%s", args[0].value_str32); |
---|
64 | NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&message, 257); |
---|
65 | } |
---|
66 | else if(MsNet_Running) { |
---|
67 | MSNet_SendChat( args[0].value_str32 ); |
---|
68 | } |
---|
69 | else { |
---|
70 | DDrConsole_PrintF("You aren't connected to a server!"); |
---|
71 | } |
---|
72 | return 0; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | uint16_t ONICALL connect_to_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
77 | { |
---|
78 | //TODO: Move this into the client initialization. Doing it like this is silly. |
---|
79 | if( NetPlatform_Initalize()) { |
---|
80 | static flatline_packet packet; |
---|
81 | memset(&client_address, 0, sizeof(sockaddr_in)); |
---|
82 | sock = NetUDPSocket_Create(27777, &client_address); |
---|
83 | address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 ); |
---|
84 | //address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1"); |
---|
85 | |
---|
86 | packet.id = CONNECT_SEND; |
---|
87 | memcpy(((connect_send*)(packet.data))->country , player_country, 2); |
---|
88 | memcpy(((connect_send*)(packet.data))->name, player_name, 256); |
---|
89 | DDrConsole_PrintF("%s", ((connect_send*)(packet.data))->name); |
---|
90 | CreateThread(NULL, 0, StartClient, &packet, 0, 0); |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | return 0; |
---|
95 | } |
---|
96 | uint16_t ONICALL status(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
97 | { |
---|
98 | int j; |
---|
99 | if(server_started) { |
---|
100 | for(j = 0; j < max_connections; j++) { |
---|
101 | |
---|
102 | if (PlayerList[j] != 0) { |
---|
103 | DDrConsole_PrintF("Client %i: %s from %s", |
---|
104 | j, |
---|
105 | PlayerList[j]->name, |
---|
106 | inet_ntoa(*( (struct in_addr*)(int*)&(PlayerList[j]->ip ) ))); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | else if(client_connected) { |
---|
111 | DDrConsole_PrintF("Connected to %s, port %i, socket %i", inet_ntoa(address.sin_addr), ntohs(address.sin_port), sock); |
---|
112 | for(j = 0; j < max_connections; j++) { |
---|
113 | |
---|
114 | if (PlayerList[j] != 0) { |
---|
115 | DDrConsole_PrintF("Client %i: %s %x", |
---|
116 | j, |
---|
117 | PlayerList[j]->name, |
---|
118 | PlayerList[j]->Chr |
---|
119 | ); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | else{} |
---|
124 | return 0; |
---|
125 | } |
---|
126 | |
---|
127 | uint16_t ONICALL addfake(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
128 | { |
---|
129 | player_info * info; |
---|
130 | info = FLrServer_AddPlayer( 0, "shinny", 0 , 1); |
---|
131 | return 0; |
---|
132 | } |
---|
133 | |
---|
134 | uint16_t ONICALL kick(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
135 | { |
---|
136 | if(server_started && PlayerList[args[0].value_int32]) |
---|
137 | { |
---|
138 | ONrCharacter_SetHitPoints(PlayerList[args[0].value_int32]->Chr, 0); |
---|
139 | FLrPlayerDisconnect(args[0].value_int32); |
---|
140 | FLsPublic_Event(EV_DISCONNECT, &args[0].value_int32); |
---|
141 | } |
---|
142 | return 0; |
---|
143 | } |
---|
144 | |
---|
145 | uint16_t ONICALL ping(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
146 | { |
---|
147 | if(server_started) |
---|
148 | { |
---|
149 | FLsPingAll(); |
---|
150 | } |
---|
151 | return 0; |
---|
152 | } |
---|
153 | |
---|
154 | CharacterObject* spawnObject = 0; |
---|
155 | char BINACHARCallback(CharacterObject* inObj, char* userdata) |
---|
156 | { |
---|
157 | if(strcmp(userdata, inObj->OSD.Name)) |
---|
158 | { |
---|
159 | return 1; |
---|
160 | } |
---|
161 | spawnObject = inObj; |
---|
162 | return 0; |
---|
163 | } |
---|
164 | uint16_t ONICALL FLrSpawnHack(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
165 | { |
---|
166 | flatline_packet new_char = {0}; |
---|
167 | int i; |
---|
168 | if(client_connected) return 0; |
---|
169 | AI2iScript_Spawn(callinfo, numargs, args, dontuse1, dontuse2, ret); |
---|
170 | if(!server_started) return 0; |
---|
171 | for(i = 0; i < 64; i++) |
---|
172 | { |
---|
173 | if(!strcmp(ONgGameState->CharacterStorage[i].Name, args[0].value_str32)) |
---|
174 | { |
---|
175 | //DDrConsole_PrintF("%s spawned, slot %i", args[0].value_str32, i); |
---|
176 | int playerlist_slot = FLr_FindEmptyListSlot(); |
---|
177 | int player_slot = i; |
---|
178 | new_char.new_player.Playernumber = playerlist_slot; |
---|
179 | new_char.id = NEW_PLAYER; |
---|
180 | OBJrObjectType_EnumerateObjects('CHAR',BINACHARCallback, (int)args[0].value_str32); |
---|
181 | // while(!spawnObject); |
---|
182 | if(spawnObject) |
---|
183 | { |
---|
184 | memcpy(&new_char.new_player.Character, spawnObject, sizeof(CharacterObject) ); |
---|
185 | } |
---|
186 | else return 1; |
---|
187 | //new_char.new_player.Character; |
---|
188 | PlayerList[playerlist_slot] = Players+player_slot; |
---|
189 | PlayerList[playerlist_slot]->spawnnumber = player_slot; |
---|
190 | PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot]; |
---|
191 | sprintf_s(PlayerList[playerlist_slot]->name, 32, "%s", PlayerList[playerlist_slot]->Chr->Name); |
---|
192 | // PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF |
---|
193 | // if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF |
---|
194 | // sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name); |
---|
195 | UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER ); |
---|
196 | PlayerList[playerlist_slot]->flags = PF_SCRIPTEDAI; |
---|
197 | PlayerList[playerlist_slot]->list_slot = playerlist_slot; |
---|
198 | return 0; |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | return 0; |
---|
203 | } |
---|
204 | |
---|
205 | uint16_t ONICALL list_players(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
206 | { |
---|
207 | int i; |
---|
208 | for(i = 0; i++; i < MAX_PLAYERS) |
---|
209 | { |
---|
210 | if(PlayerList[i]) |
---|
211 | { |
---|
212 | DDrConsole_PrintF("%i %i | %s", i, PlayerList[i]->spawnnumber, PlayerList[i]->name); |
---|
213 | } |
---|
214 | } |
---|
215 | return 0; |
---|
216 | } |
---|
217 | uint16_t ONICALL con(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
218 | { |
---|
219 | OBJrConsole_OnActivate( OBJrConsole_GetByID(args[0].value_int32), PlayerList[0]->Chr ); |
---|
220 | return 0; |
---|
221 | } |
---|
222 | |
---|
223 | uint16_t tele(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
224 | { |
---|
225 | ActiveCharacter *AC = ONrGetActiveCharacter(ONgGameState->PlayerCharacter); |
---|
226 | // AC->PhyContext->Position = AC->AimTarget; |
---|
227 | AC->PhyContext->Position.X += AC->AimVector.X; |
---|
228 | AC->PhyContext->Position.Y += AC->AimVector.Y; |
---|
229 | AC->PhyContext->Position.Z += AC->AimVector.Z; |
---|
230 | return 0; |
---|
231 | } |
---|
232 | |
---|
233 | uint16_t ONICALL mnet_login(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
---|
234 | { |
---|
235 | MSNet_Login(args[0].value_str32, args[1].value_str32); |
---|
236 | return 0; |
---|
237 | } |
---|
238 | |
---|
239 | void SLrFlatline_Initialize() |
---|
240 | { |
---|
241 | |
---|
242 | DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys); |
---|
243 | FLrInput_Update_Keys(); |
---|
244 | SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) ); |
---|
245 | SLrScript_Command_Register_Void("tele","teleports", "", tele); |
---|
246 | SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server); |
---|
247 | SLrScript_Command_Register_Void("host","Starts a server", "", start_server); |
---|
248 | SLrScript_Command_Register_Void("msg","Sends a message", "", send_message); |
---|
249 | SLrScript_Command_Register_ReturnType("name","changes your name", "name:string", sl_void, change_name); |
---|
250 | SLrScript_Command_Register_Void("status","shows the connection status", "", status); |
---|
251 | SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name); |
---|
252 | SLrScript_Command_Register_ReturnType("addbot","adds a fake client", "", sl_void, addfake); |
---|
253 | SLrScript_Command_Register_Void("kick", "Kicks a client from the server", "clientnum:int", kick); |
---|
254 | SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con); |
---|
255 | SLrScript_Command_Register_Void("ping", "pong!", "", ping); |
---|
256 | |
---|
257 | SLrScript_Command_Register_Void("login", "logs into mariusnet", "username:string password:string", mnet_login); |
---|
258 | } |
---|