| 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 | return 0;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | uint16_t ONICALL send_message(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
|
|---|
| 47 | {
|
|---|
| 48 |
|
|---|
| 49 | flatline_packet message;
|
|---|
| 50 | message.id = MESSAGE;
|
|---|
| 51 |
|
|---|
| 52 | if(server_started) {
|
|---|
| 53 | int message_size = sprintf(message.data, "%s: %s", player_name, args[0].value_str32);
|
|---|
| 54 | COrMessage_Print(message.data, "chat", 0);
|
|---|
| 55 | UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER );
|
|---|
| 56 | }
|
|---|
| 57 | else if(client_connected) {
|
|---|
| 58 | sprintf(message.data, "%s", args[0].value_str32);
|
|---|
| 59 | NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&message, 257);
|
|---|
| 60 | }
|
|---|
| 61 | else {
|
|---|
| 62 | DDrConsole_PrintF("You aren't connected to a server!");
|
|---|
| 63 | }
|
|---|
| 64 | return 0;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | uint16_t ONICALL connect_to_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
|
|---|
| 69 | {
|
|---|
| 70 | if( NetPlatform_Initalize()) {
|
|---|
| 71 | static flatline_packet packet;
|
|---|
| 72 | sock = NetUDPSocket_Create(27777);
|
|---|
| 73 | address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 );
|
|---|
| 74 | //address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1");
|
|---|
| 75 |
|
|---|
| 76 | packet.id = CONNECT_SEND;
|
|---|
| 77 | memcpy(((connect_send*)(packet.data))->country , player_country, 2);
|
|---|
| 78 | memcpy(((connect_send*)(packet.data))->name, player_name, 256);
|
|---|
| 79 | DDrConsole_PrintF("%s", ((connect_send*)(packet.data))->name);
|
|---|
| 80 | CreateThread(NULL, 0, StartClient, &packet, 0, 0);
|
|---|
| 81 |
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | return 0;
|
|---|
| 85 | }
|
|---|
| 86 | uint16_t ONICALL status(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
|
|---|
| 87 | {
|
|---|
| 88 | int j;
|
|---|
| 89 | if(server_started) {
|
|---|
| 90 | for(j = 0; j < max_connections; j++) {
|
|---|
| 91 |
|
|---|
| 92 | if (PlayerList[j] != 0) {
|
|---|
| 93 | DDrConsole_PrintF("Client %i: %s from %s",
|
|---|
| 94 | j,
|
|---|
| 95 | PlayerList[j]->name,
|
|---|
| 96 | (inet_ntoa(*( (struct in_addr*)(int*)&(PlayerList[j]->ip ) ))));
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | else if(client_connected) {
|
|---|
| 101 | DDrConsole_PrintF("Connected to %s, port %i, socket %i", inet_ntoa(address.sin_addr), ntohs(address.sin_port), sock);
|
|---|
| 102 | for(j = 0; j < max_connections; j++) {
|
|---|
| 103 |
|
|---|
| 104 | if (PlayerList[j] != 0) {
|
|---|
| 105 | DDrConsole_PrintF("Client %i: %s %x",
|
|---|
| 106 | j,
|
|---|
| 107 | PlayerList[j]->name,
|
|---|
| 108 | PlayerList[j]->Chr
|
|---|
| 109 | );
|
|---|
| 110 | }
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | else{}
|
|---|
| 114 | return 0;
|
|---|
| 115 | }
|
|---|
| 116 | uint16_t ONICALL addfake(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
|
|---|
| 117 | {
|
|---|
| 118 | player_info * info;
|
|---|
| 119 | info = FLrServer_AddPlayer( 0, "Fake", 0 );
|
|---|
| 120 | info->Actions1 = Action_Forward;
|
|---|
| 121 | return 0;
|
|---|
| 122 | }
|
|---|
| 123 | void SLrFlatline_Initialize() {
|
|---|
| 124 |
|
|---|
| 125 | DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys);
|
|---|
| 126 |
|
|---|
| 127 | SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) );
|
|---|
| 128 | SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server);
|
|---|
| 129 | SLrScript_Command_Register_Void("host","Starts a server", "", start_server);
|
|---|
| 130 | SLrScript_Command_Register_Void("msg","Sends a message", "", send_message);
|
|---|
| 131 | SLrScript_Command_Register_ReturnType("name","changes your name", "name:str", sl_void, change_name);
|
|---|
| 132 | SLrScript_Command_Register_Void("status","shows the connection status", "", status);
|
|---|
| 133 | SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name);
|
|---|
| 134 | SLrScript_Command_Register_ReturnType("addfakeclient","adds a fake client", "", sl_void, addfake);
|
|---|
| 135 | }
|
|---|