source: Daodan/src/Flatline_BSL.c@ 568

Last change on this file since 568 was 484, checked in by gumby, 15 years ago

ZOMG FLATLINE

File size: 3.9 KB
RevLine 
[484]1#include "BFW_ScriptLang.h"
2
3#include "Daodan_Patch.h"
4#include "Daodan_BSL.h"
5#include "Flatline_BSL.h"
6#include "Flatline.h"
7#include "Flatline_Server.h"
8bool server_started = 0;
9bool client_connected = 0;
10int sock = 0;
11sockaddr_in address;
12char player_name[32] = {0};
13char player_country[256] = {0};
14int update_rate = 5;
15
16uint16_t ONICALL start_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
17{
18 CreateThread(NULL, 0, StartServer, NULL, 0, 0);
19 server_started = 1;
20 return 0;
21}
22
23uint16_t ONICALL control_update_rate(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
24{
25 update_rate = args[0].value_int32;
26 server_started = 1;
27 return 0;
28}
29
30uint16_t ONICALL change_name(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
31{
32 //should also return your name...
33 sprintf(player_name, "%.31s", args[0].value_str32);
34 flatline_packet packet;
35 packet.id = CHANGE_NAME;
36 memcpy(packet.data, args[0].value_str32, 256);
37
38
39 NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&packet, 257);
40 return 0;
41}
42
43uint16_t ONICALL send_message(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
44{
45
46 flatline_packet message;
47 message.id = MESSAGE;
48
49 if(server_started) {
50 int message_size = sprintf(message.data, "%s", args[0].value_str32);
51 UDPServer_SendToAll(&message, message_size + FLATLINE_HEADER);
52 }
53 else if(client_connected) {
54 sprintf(message.data, "%s", args[0].value_str32);
55 NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&message, 257);
56 }
57 else {
58 DDrConsole_PrintF("You aren't connected to a server!");
59 }
60 return 0;
61}
62
63
64uint16_t ONICALL connect_to_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
65{
66 NetPlatform_Initalize();
67 sock = NetUDPSocket_Create(27777);
68 address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 );
69 static flatline_packet packet;
70
71 packet.id = CONNECT_SEND;
72 memcpy(((connect_send*)(packet.data))->country , player_country, 2);
73 memcpy(((connect_send*)(packet.data))->name, player_name, 256);
74 DDrConsole_PrintF("%s", ((connect_send*)(packet.data))->name);
75 CreateThread(NULL, 0, StartClient, &packet, 0, 0);
76
77
78
79 return 0;
80}
81uint16_t ONICALL status(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
82{
83 int j;
84 if(server_started) {
85 for(j = 0; j < max_connections; j++) {
86
87 if (PlayerList[j] != 0) {
88 DDrConsole_PrintF("Client %i: %s from %s",
89 j,
90 PlayerList[j]->name,
91 (inet_ntoa(*( (struct in_addr*)(int*)&(PlayerList[j]->ip ) ))));
92 }
93 }
94 }
95 else if(client_connected) {
96 DDrConsole_PrintF("Connected to %s, port %i, socket %i", inet_ntoa(address.sin_addr), ntohs(address.sin_port), sock);
97 for(j = 0; j < max_connections; j++) {
98
99 if (PlayerList[j] != 0) {
100 DDrConsole_PrintF("Client %i: %s %x",
101 j,
102 PlayerList[j]->name,
103 PlayerList[j]->Chr
104 );
105 }
106 }
107 }
108 else{}
109 return 0;
110}
111
112#include "Oni.h"
113void SLrFlatline_Initialize() {
114
115 DDrPatch_MakeCall(OniExe + 0x000FA88B, FLrInput_Update_Keys);
116 SLrGlobalVariable_Register_Int32("skip", "skips", &(((GameState*)ONgGameState)->field_40) );
117 SLrScript_Command_Register_Void("connect","Connects to a server", "address", connect_to_server);
118 SLrScript_Command_Register_Void("host","Starts a server", "", start_server);
119 SLrScript_Command_Register_Void("msg","Sends a message", "", send_message);
120 SLrScript_Command_Register_Void("name","changes your name", "name:str", change_name);
121 SLrScript_Command_Register_Void("status","shows the connection status", "", status);
122 SLrGlobalVariable_Register_String("country", "Your Multiplayer country", player_name);
123}
Note: See TracBrowser for help on using the repository browser.