source: Daodan/src/flatline/Flatline_BSL.c@ 983

Last change on this file since 983 was 878, checked in by alloc, 11 years ago

Daodan: Flatline fix

File size: 8.7 KB
Line 
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#include "Flatline_Client.h"
11
12unsigned char server_started = 0;
13unsigned char client_connected = 0;
14int sock = 0;
15sockaddr_in address;
16char player_name[32] = "Striker";
17char player_country[256] = {0};
18int update_rate = 5;
19
20#include "../Oni.h"
21#include "../Daodan_Cheater.h"
22
23uint16_t ONICALL start_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
24{
25 CreateThread(NULL, 0, StartServer, NULL, 0, 0);
26 server_started = 1;
27 return 0;
28}
29
30uint16_t ONICALL control_update_rate(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
31{
32 update_rate = args[0].val.value_int32;
33 server_started = 1;
34 return 0;
35}
36
37uint16_t ONICALL change_name(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
38{
39
40 //should also return your name...
41 sprintf(player_name, "%.31s", args[0].val.value_str32);
42 if(client_connected) {
43 flatline_packet packet;
44 packet.id = CHANGE_NAME;
45 memcpy(packet.data, args[0].val.value_str32, 256);
46 NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&packet, 257);
47 }
48 if(server_started)
49 {
50 FLsUpdateName( 0, args[0].val.value_str32 );
51 }
52 return 0;
53}
54
55uint16_t ONICALL send_message(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
56{
57
58 flatline_packet message;
59 message.id = MESSAGE;
60
61 if(server_started) {
62 int message_size = sprintf(message.data, "%s: %s", player_name, args[0].val.value_str32);
63 COrMessage_Print(message.data, "chat", 0);
64 UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER );
65 }
66 else if(client_connected) {
67 sprintf(message.data, "%s", args[0].val.value_str32);
68 NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&message, 257);
69 }
70 else if(MsNet_Running) {
71 MSNet_SendChat( args[0].val.value_str32 );
72 }
73 else {
74 DDrConsole_PrintF("You aren't connected to a server!");
75 }
76 return 0;
77}
78
79
80uint16_t ONICALL connect_to_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
81{
82 //TODO: Move this into the client initialization. Doing it like this is silly.
83 FLcConnect(inet_addr(args[0].val.value_str32), htons(FLATLINE_PORT));
84 return 0;
85}
86uint16_t ONICALL status(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
87{
88 int j;
89 if(server_started) {
90 for(j = 0; j < max_connections; j++) {
91
92 if (PlayerList[j] != 0) {
93 DDrConsole_PrintF("Client %i: %s from %s",
94 j,
95 PlayerList[j]->name,
96 inet_ntoa(*( (struct in_addr*)(int*)&(PlayerList[j]->ip ) )));
97 }
98 }
99 }
100 else if(client_connected) {
101 DDrConsole_PrintF("Connected to %s, port %i, socket %i", inet_ntoa(address.sin_addr), ntohs(address.sin_port), sock);
102 for(j = 0; j < max_connections; j++) {
103
104 if (PlayerList[j] != 0) {
105 DDrConsole_PrintF("Client %i: %s %x",
106 j,
107 PlayerList[j]->name,
108 PlayerList[j]->Chr
109 );
110 }
111 }
112 }
113 else{}
114 return 0;
115}
116
117uint16_t ONICALL addfake(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
118{
119 player_info * info;
120 info = FLrServer_AddPlayer( 0, "shinny", 0 , 1);
121 return 0;
122}
123
124uint16_t ONICALL kick(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
125{
126 if(server_started && PlayerList[args[0].val.value_int32])
127 {
128 ONrCharacter_SetHitPoints(PlayerList[args[0].val.value_int32]->Chr, 0);
129 FLrPlayerDisconnect(args[0].val.value_int32);
130 FLsPublic_Event(EV_DISCONNECT, &args[0].val.value_int32);
131 }
132 return 0;
133}
134
135uint16_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
144CharacterObject* spawnObject = 0;
145char 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}
154uint16_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].val.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].val.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 /*THIS MIGHT BE BAD*/ snprintf(PlayerList[playerlist_slot]->name, 32, "%s", PlayerList[playerlist_slot]->Chr->Name);
182 // PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
183 // if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF
184 // sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name);
185 UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
186 PlayerList[playerlist_slot]->flags = PF_SCRIPTEDAI;
187 PlayerList[playerlist_slot]->list_slot = playerlist_slot;
188 return 0;
189 }
190 }
191
192 return 0;
193}
194
195uint16_t ONICALL list_players(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
196{
197 int i;
198 for(i = 0; i++; i < MAX_PLAYERS)
199 {
200 if(PlayerList[i])
201 {
202 DDrConsole_PrintF("%i %i | %s", i, PlayerList[i]->spawnnumber, PlayerList[i]->name);
203 }
204 }
205 return 0;
206}
207uint16_t ONICALL con(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
208{
209 OBJrConsole_OnActivate( OBJrConsole_GetByID(args[0].val.value_int32), PlayerList[0]->Chr );
210 return 0;
211}
212
213uint16_t ONICALL tele(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
214{
215 ActiveCharacter *AC = ONrGetActiveCharacter(ONgGameState->PlayerCharacter);
216// AC->PhyContext->Position = AC->AimTarget;
217 AC->PhyContext->Position.X += AC->AimVector.X;
218 AC->PhyContext->Position.Y += AC->AimVector.Y;
219 AC->PhyContext->Position.Z += AC->AimVector.Z;
220 return 0;
221}
222
223uint16_t ONICALL mnet_login(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
224{
225 MSNet_Login(args[0].val.value_str32, args[1].val.value_str32);
226 return 0;
227}
228
229extern uint16_t ONICALL mnet_joingame(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret);
230
231void SLrFlatline_Initialize()
232{
233
234 DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys);
235 FLrInput_Update_Keys();
236 SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) );
237 SLrScript_Command_Register_Void("tele","teleports", "", tele);
238 SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server);
239 SLrScript_Command_Register_Void("host","Starts a server", "", start_server);
240 SLrScript_Command_Register_Void("msg","Sends a message", "", send_message);
241 SLrScript_Command_Register_ReturnType("name","changes your name", "name:string", sl_void, change_name);
242 SLrScript_Command_Register_Void("status","shows the connection status", "", status);
243 //SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name);
244 SLrScript_Command_Register_ReturnType("addbot","adds a fake client", "", sl_void, addfake);
245 SLrScript_Command_Register_Void("kick", "Kicks a client from the server", "clientnum:int", kick);
246 SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con);
247 SLrScript_Command_Register_Void("ping", "pong!", "", ping);
248
249 SLrScript_Command_Register_Void("login", "logs into mariusnet", "username:string password:string", mnet_login);
250 SLrScript_Command_Register_Void("join", "joins a mariusnet game", "index:int", mnet_joingame);
251}
Note: See TracBrowser for help on using the repository browser.