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 | PlayerDisconnect(args[0].value_int32);
|
---|
131 | return 0;
|
---|
132 | }
|
---|
133 |
|
---|
134 | CharacterObject* spawnObject = 0;
|
---|
135 | char BINACHARCallback(CharacterObject* inObj, char* userdata)
|
---|
136 | {
|
---|
137 | if(strcmp(userdata, inObj->OSD.Name))
|
---|
138 | {
|
---|
139 | return 1;
|
---|
140 | }
|
---|
141 | spawnObject = inObj;
|
---|
142 | return 0;
|
---|
143 | }
|
---|
144 | uint16_t ONICALL FLrSpawnHack(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
|
---|
145 | {
|
---|
146 | flatline_packet new_char = {0};
|
---|
147 | int i;
|
---|
148 | if(client_connected) return 0;
|
---|
149 | AI2iScript_Spawn(callinfo, numargs, args, dontuse1, dontuse2, ret);
|
---|
150 | if(!server_started) return 0;
|
---|
151 | for(i = 0; i < 64; i++)
|
---|
152 | {
|
---|
153 | if(!strcmp(ONgGameState->CharacterStorage[i].Name, args[0].value_str32))
|
---|
154 | {
|
---|
155 | //DDrConsole_PrintF("%s spawned, slot %i", args[0].value_str32, i);
|
---|
156 | int playerlist_slot = FLr_FindEmptyListSlot();
|
---|
157 | int player_slot = i;
|
---|
158 | new_char.new_player.Playernumber = playerlist_slot;
|
---|
159 | new_char.id = NEW_PLAYER;
|
---|
160 | OBJrObjectType_EnumerateObjects('CHAR',BINACHARCallback, (int)args[0].value_str32);
|
---|
161 | // while(!spawnObject);
|
---|
162 | if(spawnObject)
|
---|
163 | {
|
---|
164 | memcpy(&new_char.new_player.Character, spawnObject, sizeof(CharacterObject) );
|
---|
165 | }
|
---|
166 | else return 1;
|
---|
167 | //new_char.new_player.Character;
|
---|
168 | PlayerList[playerlist_slot] = Players+player_slot;
|
---|
169 | PlayerList[playerlist_slot]->spawnnumber = player_slot;
|
---|
170 | PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot];
|
---|
171 | // PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
|
---|
172 | // if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF
|
---|
173 | // sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name);
|
---|
174 | UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
|
---|
175 | PlayerList[playerlist_slot]->flags = PF_SCRIPTEDAI;
|
---|
176 | PlayerList[playerlist_slot]->list_slot = playerlist_slot;
|
---|
177 | return 0;
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | return 0;
|
---|
182 | }
|
---|
183 |
|
---|
184 | uint16_t ONICALL list_players(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
|
---|
185 | {
|
---|
186 | int i;
|
---|
187 | for(i = 0; i++; i < MAX_PLAYERS)
|
---|
188 | {
|
---|
189 | if(PlayerList[i])
|
---|
190 | {
|
---|
191 | DDrConsole_PrintF("%i %i | %s", i, PlayerList[i]->spawnnumber, PlayerList[i]->name);
|
---|
192 | }
|
---|
193 | }
|
---|
194 | return 0;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | void SLrFlatline_Initialize() {
|
---|
199 |
|
---|
200 | DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys);
|
---|
201 | FLrInput_Update_Keys();
|
---|
202 | SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) );
|
---|
203 | SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server);
|
---|
204 | SLrScript_Command_Register_Void("host","Starts a server", "", start_server);
|
---|
205 | SLrScript_Command_Register_Void("msg","Sends a message", "", send_message);
|
---|
206 | SLrScript_Command_Register_ReturnType("name","changes your name", "name:string", sl_void, change_name);
|
---|
207 | SLrScript_Command_Register_Void("status","shows the connection status", "", status);
|
---|
208 | SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name);
|
---|
209 | SLrScript_Command_Register_ReturnType("addbot","adds a fake client", "", sl_void, addfake);
|
---|
210 | SLrScript_Command_Register_Void("kick", "Kicks a client from the server", "clientnum:int", kick);
|
---|
211 | //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);
|
---|
212 | }
|
---|