source: Daodan/MSVC/Flatline_BSL.c@ 682

Last change on this file since 682 was 589, checked in by gumby, 13 years ago

stuff

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