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 |
sprintf_s(PlayerList[0]->Chr->Name,32, 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 |
if( NetPlatform_Initalize()) { |
75 |
static flatline_packet packet; |
76 |
sock = NetUDPSocket_Create(27777); |
77 |
address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 ); |
78 |
//address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1"); |
79 |
|
80 |
packet.id = CONNECT_SEND; |
81 |
memcpy(((connect_send*)(packet.data))->country , player_country, 2); |
82 |
memcpy(((connect_send*)(packet.data))->name, player_name, 256); |
83 |
DDrConsole_PrintF("%s", ((connect_send*)(packet.data))->name); |
84 |
CreateThread(NULL, 0, StartClient, &packet, 0, 0); |
85 |
|
86 |
} |
87 |
|
88 |
return 0; |
89 |
} |
90 |
uint16_t ONICALL status(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
91 |
{ |
92 |
int j; |
93 |
if(server_started) { |
94 |
for(j = 0; j < max_connections; j++) { |
95 |
|
96 |
if (PlayerList[j] != 0) { |
97 |
DDrConsole_PrintF("Client %i: %s from %s", |
98 |
j, |
99 |
PlayerList[j]->name, |
100 |
inet_ntoa(*( (struct in_addr*)(int*)&(PlayerList[j]->ip ) ))); |
101 |
} |
102 |
} |
103 |
} |
104 |
else if(client_connected) { |
105 |
DDrConsole_PrintF("Connected to %s, port %i, socket %i", inet_ntoa(address.sin_addr), ntohs(address.sin_port), sock); |
106 |
for(j = 0; j < max_connections; j++) { |
107 |
|
108 |
if (PlayerList[j] != 0) { |
109 |
DDrConsole_PrintF("Client %i: %s %x", |
110 |
j, |
111 |
PlayerList[j]->name, |
112 |
PlayerList[j]->Chr |
113 |
); |
114 |
} |
115 |
} |
116 |
} |
117 |
else{} |
118 |
return 0; |
119 |
} |
120 |
|
121 |
uint16_t ONICALL addfake(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
122 |
{ |
123 |
player_info * info; |
124 |
info = FLrServer_AddPlayer( 0, "shinny", 0 , 1); |
125 |
return 0; |
126 |
} |
127 |
|
128 |
uint16_t ONICALL kick(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
129 |
{ |
130 |
FLrPlayerDisconnect(args[0].value_int32 - 1); |
131 |
FLsPublic_Event(EV_DISCONNECT, &args[0].value_int32); |
132 |
return 0; |
133 |
} |
134 |
|
135 |
uint16_t ONICALL ping(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
136 |
{ |
137 |
if(server_started) |
138 |
{ |
139 |
FLsPingAll(); |
140 |
} |
141 |
return 0; |
142 |
} |
143 |
|
144 |
CharacterObject* spawnObject = 0; |
145 |
char BINACHARCallback(CharacterObject* inObj, char* userdata) |
146 |
{ |
147 |
if(strcmp(userdata, inObj->OSD.Name)) |
148 |
{ |
149 |
return 1; |
150 |
} |
151 |
spawnObject = inObj; |
152 |
return 0; |
153 |
} |
154 |
uint16_t ONICALL FLrSpawnHack(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
155 |
{ |
156 |
flatline_packet new_char = {0}; |
157 |
int i; |
158 |
if(client_connected) return 0; |
159 |
AI2iScript_Spawn(callinfo, numargs, args, dontuse1, dontuse2, ret); |
160 |
if(!server_started) return 0; |
161 |
for(i = 0; i < 64; i++) |
162 |
{ |
163 |
if(!strcmp(ONgGameState->CharacterStorage[i].Name, args[0].value_str32)) |
164 |
{ |
165 |
//DDrConsole_PrintF("%s spawned, slot %i", args[0].value_str32, i); |
166 |
int playerlist_slot = FLr_FindEmptyListSlot(); |
167 |
int player_slot = i; |
168 |
new_char.new_player.Playernumber = playerlist_slot; |
169 |
new_char.id = NEW_PLAYER; |
170 |
OBJrObjectType_EnumerateObjects('CHAR',BINACHARCallback, (int)args[0].value_str32); |
171 |
// while(!spawnObject); |
172 |
if(spawnObject) |
173 |
{ |
174 |
memcpy(&new_char.new_player.Character, spawnObject, sizeof(CharacterObject) ); |
175 |
} |
176 |
else return 1; |
177 |
//new_char.new_player.Character; |
178 |
PlayerList[playerlist_slot] = Players+player_slot; |
179 |
PlayerList[playerlist_slot]->spawnnumber = player_slot; |
180 |
PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot]; |
181 |
// PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF |
182 |
// if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF |
183 |
// sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name); |
184 |
UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER ); |
185 |
PlayerList[playerlist_slot]->flags = PF_SCRIPTEDAI; |
186 |
PlayerList[playerlist_slot]->list_slot = playerlist_slot; |
187 |
return 0; |
188 |
} |
189 |
} |
190 |
|
191 |
return 0; |
192 |
} |
193 |
|
194 |
uint16_t ONICALL list_players(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
195 |
{ |
196 |
int i; |
197 |
for(i = 0; i++; i < MAX_PLAYERS) |
198 |
{ |
199 |
if(PlayerList[i]) |
200 |
{ |
201 |
DDrConsole_PrintF("%i %i | %s", i, PlayerList[i]->spawnnumber, PlayerList[i]->name); |
202 |
} |
203 |
} |
204 |
return 0; |
205 |
} |
206 |
uint16_t ONICALL con(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
207 |
{ |
208 |
OBJrConsole_OnActivate( OBJrConsole_GetByID(args[0].value_int32), PlayerList[0]->Chr ); |
209 |
return 0; |
210 |
} |
211 |
|
212 |
|
213 |
void SLrFlatline_Initialize() |
214 |
{ |
215 |
|
216 |
DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys); |
217 |
FLrInput_Update_Keys(); |
218 |
SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) ); |
219 |
SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server); |
220 |
SLrScript_Command_Register_Void("host","Starts a server", "", start_server); |
221 |
SLrScript_Command_Register_Void("msg","Sends a message", "", send_message); |
222 |
SLrScript_Command_Register_ReturnType("name","changes your name", "name:string", sl_void, change_name); |
223 |
SLrScript_Command_Register_Void("status","shows the connection status", "", status); |
224 |
SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name); |
225 |
SLrScript_Command_Register_ReturnType("addbot","adds a fake client", "", sl_void, addfake); |
226 |
SLrScript_Command_Register_Void("kick", "Kicks a client from the server", "clientnum:int", kick); |
227 |
SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con); |
228 |
//SLrScript_Command_Register_ReturnType("ai2_spawn","creates and starts an AI from a character object","ai_name:string [force_spawn:string{\"force\"} | ]", sl_void, spawnAI); |
229 |
SLrScript_Command_Register_Void("ping", "pong!", "", ping); |
230 |
} |