#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); } 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, "Fake", 0 ); info->Actions1 = Action_Forward; 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); 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:str", 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("addfakeclient","adds a fake client", "", sl_void, addfake); }