#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] = {0}; char player_country[256] = {0}; int update_rate = 5; 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); 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", args[0].value_str32); UDPServer_SendToAll(&message, message_size + 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) { NetPlatform_Initalize(); 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 ); static flatline_packet packet; 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; } #include "Oni.h" void SLrFlatline_Initialize() { DDrPatch_MakeCall(OniExe + 0x000FA88B, FLrInput_Update_Keys); SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) ); SLrScript_Command_Register_Void("connect","Connects to a server", "address", 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_Void("name","changes your name", "name:str", change_name); SLrScript_Command_Register_Void("status","shows the connection status", "", status); SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name); }