source: Daodan/src/Flatline.h@ 484

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

ZOMG FLATLINE

File size: 4.2 KB
Line 
1#pragma once
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <time.h>
6//#define DDrStartupMessage printf
7
8#include <string.h>
9#include <stdbool.h>
10#include <stdint.h>
11
12#define thread __thread
13
14#ifdef WIN32
15#include <winsock2.h>
16#include "Flatline_Win32.h"
17#else
18#include <sys/ioctl.h>
19#include <sys/types.h>
20#include <sys/socket.h>
21#include <unistd.h>
22#include <stropts.h>
23#include <arpa/inet.h>
24#include <netinet/in.h>
25
26#define NetPlatform_Initalize() /* */
27#define NetPlatform_Shutdown() /* */
28#define closesocket close
29#define ioctlsocket ioctl
30#endif
31
32#include "Daodan.h"
33#include "BFW_Utility.h"
34#include "Daodan_Console.h"
35#include "Oni_Character.h"
36
37
38#define pad1_size (sizeof(int64_t) - sizeof(short))
39#define pad2_size (128 - (sizeof(short) + pad1_size + sizeof(int64_t)))
40
41typedef struct {
42 short ss_family;
43 char pad1[pad1_size];
44 uint64_t pad64;
45 char pad2[pad2_size];
46} sockaddr_storage;
47
48typedef struct sockaddr sockaddr;
49typedef struct sockaddr_in sockaddr_in;
50typedef sockaddr_storage sockaddr_in6;
51
52bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from));
53bool NetUDPServer_Send(sockaddr* address, char* data, int datalen);
54
55int NetUDPSocket_Create(uint16_t port);
56int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen);
57void NetUDPSocket_Close(int sock);
58bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen);
59
60DWORD WINAPI StartServer(void* lol);
61DWORD WINAPI StartClient(void* lol);
62
63//oh snap, I just realized this is rossy's version of flatline_packet. :|
64typedef struct {
65 char signature[8];
66 uint16_t protocol_version;
67 char data[0]; //data[0] doesn't work well with simple casts, btw. If you allocate enough space for a handshake_packet
68} handshake_packet; //there won't be enough room for data. You would have to manually manage the memory (ew)
69
70//initial connection
71typedef struct {
72 char country[2];
73 char name[256];
74} connect_send; //signature="CONNECT\0"
75
76//reply to connection.
77//goodtogo is if it is going to let you in
78//message is optional, only used for denial message
79typedef struct {
80 bool goodtogo;
81 int player_slot;
82 char message[256];
83} connect_reply;
84
85//um, status of the server? :/
86typedef struct {
87 char name[256];
88 uint32_t numplayers; //signature="STATUS\0\0"
89} server_status;
90
91typedef struct {
92 uint16_t Playernumber;
93 CharacterObject Character;
94} new_player;
95extern int update_rate;
96
97typedef struct {
98 float MouseDeltaX;
99 float MouseDeltaY;
100 uint32_t Actions1;
101 uint32_t Actions2;
102} input_struct;
103
104//
105typedef struct {
106 uint16_t PlayerNum;
107 Vector3 Position;
108 Vector3 LastPosition;
109 Vector3 Location;
110 float Facing;
111 float DesiredFacing;
112 float CosmeticFacing;
113 uint32_t Health;
114 uint32_t MaxHealth;
115 input_struct Inputs;
116 uint16_t Frame;
117} player_data;
118
119//used for storing data about each player
120typedef struct {
121 char id;
122 int packet_index;
123 char data[1080];
124} flatline_packet;
125#define FLATLINE_HEADER sizeof(flatline_packet)-sizeof(char)*1080
126
127bool FLrServer_PacketCallback(char* data, int datalen, int from);
128bool FLrServer_Run();
129bool FLrClient_Run(flatline_packet* packet);
130extern int sock;
131
132enum {
133 CONNECT_SEND,
134 CONNECT_REPLY,
135 STATUS,
136 MESSAGE,
137 CHANGE_NAME,
138 ECHO,
139 NEW_PLAYER,
140 PLAYER_INPUT,
141 PLAYER_DATA,
142};
143
144
145typedef struct {
146 int ip;
147 char name[32];
148 char country[2];
149 Character* Chr;
150 uint16_t spawnnumber;
151 uint16_t list_slot;
152 uint32_t Actions1;
153 uint32_t Actions2;
154 float MouseDeltaX;
155 float MouseDeltaY;
156} player_info;
157
158player_info * FLr_FindEmptySlot();
159uint16_t FLr_FindEmptyListSlot();
160void * ONICALL FLrInput_Update_Keys(void);
161
162void NetCatchError();
163#define MAX_PLAYERS 128
164#define CONNECTION_TIMEOUT 15
165#define MAX_CONNECTIONS 32
166#define NetTCPSocket_Send NetUDPSocket_Send
167#define NetTCPServer_Send NetUDPServer_Send
168extern int client_sock;
169//these two could probably be combined
170extern sockaddr_in client_address;
171extern sockaddr_in address;
172extern player_info Players[];
173extern player_info * PlayerList[];
174int UDPServer_SendToAll(void* packet, int size);
175extern bool client_connected;
176extern bool server_started;
177extern char player_name[];
Note: See TracBrowser for help on using the repository browser.