| 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 |
//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 |
FLrPlayerDisconnect(args[0].value_int32); |
| 132 |
FLsPublic_Event(EV_DISCONNECT, &args[0].value_int32); |
| 133 |
return 0; |
| 134 |
} |
| 135 |
|
| 136 |
uint16_t ONICALL ping(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 137 |
{ |
| 138 |
if(server_started) |
| 139 |
{ |
| 140 |
FLsPingAll(); |
| 141 |
} |
| 142 |
return 0; |
| 143 |
} |
| 144 |
|
| 145 |
CharacterObject* spawnObject = 0; |
| 146 |
char BINACHARCallback(CharacterObject* inObj, char* userdata) |
| 147 |
{ |
| 148 |
if(strcmp(userdata, inObj->OSD.Name)) |
| 149 |
{ |
| 150 |
return 1; |
| 151 |
} |
| 152 |
spawnObject = inObj; |
| 153 |
return 0; |
| 154 |
} |
| 155 |
uint16_t ONICALL FLrSpawnHack(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 156 |
{ |
| 157 |
flatline_packet new_char = {0}; |
| 158 |
int i; |
| 159 |
if(client_connected) return 0; |
| 160 |
AI2iScript_Spawn(callinfo, numargs, args, dontuse1, dontuse2, ret); |
| 161 |
if(!server_started) return 0; |
| 162 |
for(i = 0; i < 64; i++) |
| 163 |
{ |
| 164 |
if(!strcmp(ONgGameState->CharacterStorage[i].Name, args[0].value_str32)) |
| 165 |
{ |
| 166 |
//DDrConsole_PrintF("%s spawned, slot %i", args[0].value_str32, i); |
| 167 |
int playerlist_slot = FLr_FindEmptyListSlot(); |
| 168 |
int player_slot = i; |
| 169 |
new_char.new_player.Playernumber = playerlist_slot; |
| 170 |
new_char.id = NEW_PLAYER; |
| 171 |
OBJrObjectType_EnumerateObjects('CHAR',BINACHARCallback, (int)args[0].value_str32); |
| 172 |
// while(!spawnObject); |
| 173 |
if(spawnObject) |
| 174 |
{ |
| 175 |
memcpy(&new_char.new_player.Character, spawnObject, sizeof(CharacterObject) ); |
| 176 |
} |
| 177 |
else return 1; |
| 178 |
//new_char.new_player.Character; |
| 179 |
PlayerList[playerlist_slot] = Players+player_slot; |
| 180 |
PlayerList[playerlist_slot]->spawnnumber = player_slot; |
| 181 |
PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot]; |
| 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 |
|
| 195 |
uint16_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 |
} |
| 207 |
uint16_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].value_int32), PlayerList[0]->Chr ); |
| 210 |
return 0; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
void SLrFlatline_Initialize() |
| 215 |
{ |
| 216 |
|
| 217 |
DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys); |
| 218 |
FLrInput_Update_Keys(); |
| 219 |
SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) ); |
| 220 |
SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server); |
| 221 |
SLrScript_Command_Register_Void("host","Starts a server", "", start_server); |
| 222 |
SLrScript_Command_Register_Void("msg","Sends a message", "", send_message); |
| 223 |
SLrScript_Command_Register_ReturnType("name","changes your name", "name:string", sl_void, change_name); |
| 224 |
SLrScript_Command_Register_Void("status","shows the connection status", "", status); |
| 225 |
SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name); |
| 226 |
SLrScript_Command_Register_ReturnType("addbot","adds a fake client", "", sl_void, addfake); |
| 227 |
SLrScript_Command_Register_Void("kick", "Kicks a client from the server", "clientnum:int", kick); |
| 228 |
SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con); |
| 229 |
SLrScript_Command_Register_Void("ping", "pong!", "", ping); |
| 230 |
} |