source: Daodan/src/Flatline.h @ 486

Last change on this file since 486 was 486, checked in by gumby, 13 years ago

Fixed(?) Code.

File size: 4.4 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        char Animation[32];
118        uint16_t AnimationToState;
119        uint16_t AnimationFromState;
120        uint16_t AnimationType;
121        uint16_t NextAnimationType;
122        uint16_t AnimationType2;
123} player_data;
124
125//used for storing data about each player
126typedef struct {
127        char id;
128        int  packet_index;
129        char data[1080];       
130} flatline_packet;
131#define FLATLINE_HEADER sizeof(flatline_packet)-sizeof(char)*1080
132
133bool FLrServer_PacketCallback(char* data, int datalen, int from);
134bool FLrServer_Run();
135bool FLrClient_Run(flatline_packet* packet);
136extern int sock;
137
138enum {
139        CONNECT_SEND,
140        CONNECT_REPLY,
141        STATUS,
142        MESSAGE,
143        CHANGE_NAME,
144        ECHO,
145        NEW_PLAYER,
146        PLAYER_INPUT,
147        PLAYER_DATA,
148};
149
150
151typedef struct {
152        int      ip;
153        char name[32];
154        char country[2];
155        Character* Chr;
156        uint16_t spawnnumber;
157        uint16_t list_slot;
158        uint32_t Actions1;
159        uint32_t Actions2;
160        float MouseDeltaX;
161        float MouseDeltaY;
162} player_info;
163
164player_info * FLr_FindEmptySlot();
165uint16_t FLr_FindEmptyListSlot();
166void * ONICALL FLrInput_Update_Keys(void);
167
168void NetCatchError();
169#define MAX_PLAYERS 128
170#define CONNECTION_TIMEOUT 15
171#define MAX_CONNECTIONS 32
172#define NetTCPSocket_Send NetUDPSocket_Send
173#define NetTCPServer_Send NetUDPServer_Send
174extern int client_sock;
175//these two could probably be combined
176extern sockaddr_in client_address;
177extern sockaddr_in address;
178extern player_info Players[];
179extern player_info * PlayerList[];
180int UDPServer_SendToAll(void* packet, int size);
181extern bool client_connected;
182extern bool server_started;
183extern char player_name[];
Note: See TracBrowser for help on using the repository browser.