source: Daodan/MSVC/Flatline_BSL.c@ 572

Last change on this file since 572 was 569, checked in by gumby, 14 years ago

Fixes, fixes, everywhere

File size: 4.9 KB
RevLine 
[567]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"
9bool server_started = 0;
10bool client_connected = 0;
11int sock = 0;
12sockaddr_in address;
13char player_name[32] = "Striker";
14char player_country[256] = {0};
15int update_rate = 5;
16#include "Oni.h"
17#include "Daodan_Cheater.h"
18uint16_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
25uint16_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
32uint16_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
46uint16_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
68uint16_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}
86uint16_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}
[569]116
[568]117uint16_t ONICALL addfake(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
118{
119 player_info * info;
120info = FLrServer_AddPlayer( 0, "Fake", 0 );
121info->Actions1 = Action_Forward;
122return 0;
123}
[569]124
125uint16_t ONICALL list_players(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
126{
127 int i;
128 for(i = 0; i++; i < MAX_PLAYERS)
129 {
130 if(PlayerList[i])
131 {
132 DDrConsole_PrintF("%i %i | %s", i, PlayerList[i]->spawnnumber, PlayerList[i]->name);
133 }
134 }
135return 0;
136}
137
138
[567]139void SLrFlatline_Initialize() {
140
[568]141 DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys);
142
[567]143 SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) );
144 SLrScript_Command_Register_ReturnType("connect","Connects to a server", "ip:string", sl_void, connect_to_server);
145 SLrScript_Command_Register_Void("host","Starts a server", "", start_server);
146 SLrScript_Command_Register_Void("msg","Sends a message", "", send_message);
[568]147 SLrScript_Command_Register_ReturnType("name","changes your name", "name:str", sl_void, change_name);
[567]148 SLrScript_Command_Register_Void("status","shows the connection status", "", status);
149 SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name);
[568]150 SLrScript_Command_Register_ReturnType("addfakeclient","adds a fake client", "", sl_void, addfake);
[567]151}
Note: See TracBrowser for help on using the repository browser.