#include #include "BFW_ScriptLang.h" #include "Daodan_Patch.h" #include "Daodan_BSL.h" #include "Flatline_BSL.h" #include "Flatline.h" #include "Flatline_Server.h" bool server_started = 0; bool client_connected = 0; int sock = 0; sockaddr_in address; char player_name[32] = "Striker"; char player_country[256] = {0}; int update_rate = 5; #include "Oni.h" #include "Daodan_Cheater.h" uint16_t ONICALL start_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { CreateThread(NULL, 0, StartServer, NULL, 0, 0); server_started = 1; return 0; } uint16_t ONICALL control_update_rate(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { update_rate = args[0].value_int32; server_started = 1; return 0; } uint16_t ONICALL change_name(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { //should also return your name... sprintf(player_name, "%.31s", args[0].value_str32); if(client_connected) { flatline_packet packet; packet.id = CHANGE_NAME; memcpy(packet.data, args[0].value_str32, 256); NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&packet, 257); } if(server_started) { sprintf_s(PlayerList[0]->Chr->Name,32, args[0].value_str32); } return 0; } uint16_t ONICALL send_message(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { flatline_packet message; message.id = MESSAGE; if(server_started) { int message_size = sprintf(message.data, "%s: %s", player_name, args[0].value_str32); COrMessage_Print(message.data, "chat", 0); UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER ); } else if(client_connected) { sprintf(message.data, "%s", args[0].value_str32); NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&message, 257); } else { DDrConsole_PrintF("You aren't connected to a server!"); } return 0; } uint16_t ONICALL connect_to_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { if( NetPlatform_Initalize()) { static flatline_packet packet; sock = NetUDPSocket_Create(27777); address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 ); //address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1"); packet.id = CONNECT_SEND; memcpy(((connect_send*)(packet.data))->country , player_country, 2); memcpy(((connect_send*)(packet.data))->name, player_name, 256); DDrConsole_PrintF("%s", ((connect_send*)(packet.data))->name); CreateThread(NULL, 0, StartClient, &packet, 0, 0); } return 0; } uint16_t ONICALL status(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { int j; if(server_started) { for(j = 0; j < max_connections; j++) { if (PlayerList[j] != 0) { DDrConsole_PrintF("Client %i: %s from %s", j, PlayerList[j]->name, (inet_ntoa(*( (struct in_addr*)(int*)&(PlayerList[j]->ip ) )))); } } } else if(client_connected) { DDrConsole_PrintF("Connected to %s, port %i, socket %i", inet_ntoa(address.sin_addr), ntohs(address.sin_port), sock); for(j = 0; j < max_connections; j++) { if (PlayerList[j] != 0) { DDrConsole_PrintF("Client %i: %s %x", j, PlayerList[j]->name, PlayerList[j]->Chr ); } } } else{} return 0; } uint16_t ONICALL addfake(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { player_info * info; info = FLrServer_AddPlayer( 0, "shinny", 0 , 1); return 0; } uint16_t ONICALL kick(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { PlayerDisconnect(args[0].value_int32); return 0; } CharacterObject* spawnObject = 0; char BINACHARCallback(CharacterObject* inObj, char* userdata) { if(strcmp(userdata, inObj->OSD.Name)) { return 1; } spawnObject = inObj; return 0; } uint16_t ONICALL FLrSpawnHack(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { flatline_packet new_char = {0}; int i; if(client_connected) return 0; AI2iScript_Spawn(callinfo, numargs, args, dontuse1, dontuse2, ret); if(!server_started) return 0; for(i = 0; i < 64; i++) { if(!strcmp(ONgGameState->CharacterStorage[i].Name, args[0].value_str32)) { //DDrConsole_PrintF("%s spawned, slot %i", args[0].value_str32, i); int playerlist_slot = FLr_FindEmptyListSlot(); int player_slot = i; new_char.new_player.Playernumber = playerlist_slot; new_char.id = NEW_PLAYER; OBJrObjectType_EnumerateObjects('CHAR',BINACHARCallback, (int)args[0].value_str32); // while(!spawnObject); if(spawnObject) { memcpy(&new_char.new_player.Character, spawnObject, sizeof(CharacterObject) ); } else return 1; //new_char.new_player.Character; PlayerList[playerlist_slot] = Players+player_slot; PlayerList[playerlist_slot]->spawnnumber = player_slot; PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot]; // PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF // if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF // sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name); UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER ); PlayerList[playerlist_slot]->flags = PF_SCRIPTEDAI; PlayerList[playerlist_slot]->list_slot = playerlist_slot; return 0; } } return 0; } uint16_t ONICALL list_players(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { int i; for(i = 0; i++; i < MAX_PLAYERS) { if(PlayerList[i]) { DDrConsole_PrintF("%i %i | %s", i, PlayerList[i]->spawnnumber, PlayerList[i]->name); } } return 0; } void SLrFlatline_Initialize() { DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys); FLrInput_Update_Keys(); SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) ); SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server); SLrScript_Command_Register_Void("host","Starts a server", "", start_server); SLrScript_Command_Register_Void("msg","Sends a message", "", send_message); SLrScript_Command_Register_ReturnType("name","changes your name", "name:string", sl_void, change_name); SLrScript_Command_Register_Void("status","shows the connection status", "", status); SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name); SLrScript_Command_Register_ReturnType("addbot","adds a fake client", "", sl_void, addfake); SLrScript_Command_Register_Void("kick", "Kicks a client from the server", "clientnum:int", kick); //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); }