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