- Timestamp:
- Feb 7, 2011, 6:34:47 AM (14 years ago)
- Location:
- Daodan/MSVC
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/MSVC/Flatline.c
r586 r587 592 592 bool FlatlineInitialize() 593 593 { 594 595 594 memset( Players, 0, sizeof( player_info ) * MAX_PLAYERS ); 596 595 memset( PlayerList, 0, 4 * MAX_PLAYERS ); -
Daodan/MSVC/Flatline.h
r586 r587 38 38 #include "Flatline_Packet.h" 39 39 40 #define pad1_size (sizeof(int64_t) - sizeof(short)) 41 #define pad2_size (128 - (sizeof(short) + pad1_size + sizeof(int64_t))) 42 43 #define breakpoint asm("int3") 44 45 typedef struct { 46 short ss_family; 47 char pad1[pad1_size]; 48 uint64_t pad64; 49 char pad2[pad2_size]; 50 } sockaddr_storage; 51 52 typedef struct sockaddr sockaddr; 53 typedef struct sockaddr_in sockaddr_in; 54 typedef sockaddr_storage sockaddr_in6; 55 56 bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from)); 57 bool NetUDPServer_Send(sockaddr* address, char* data, int datalen); 58 59 int NetUDPSocket_Create(uint16_t port); 60 int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen); 61 void NetUDPSocket_Close(int sock); 62 bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen); 40 41 //#define breakpoint asm("int3") 42 43 44 #include "Flatline_Net.h" 63 45 64 46 DWORD WINAPI StartServer(void* lol); … … 167 149 typedef struct { 168 150 //int FLATLINE; 169 int id; 170 int packet_index; 151 short signature; 152 short id; 153 int size; 154 //int packet_index; 171 155 union 172 156 { -
Daodan/MSVC/Flatline_BSL.c
r586 r587 7 7 #include "Flatline.h" 8 8 #include "Flatline_Server.h" 9 #include "Mariusnet_Public.h" 9 10 bool server_started = 0; 10 11 bool client_connected = 0; … … 75 76 if( NetPlatform_Initalize()) { 76 77 static flatline_packet packet; 77 sock = NetUDPSocket_Create(27777); 78 memset(&client_address, 0, sizeof(sockaddr_in)); 79 sock = NetUDPSocket_Create(27777, &client_address); 78 80 address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 ); 79 81 //address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1"); … … 225 227 return 0; 226 228 } 229 230 uint16_t ONICALL mnet_login(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) 231 { 232 MSNet_Login(args[0].value_str32, args[1].value_str32); 233 return 0; 234 } 235 227 236 void SLrFlatline_Initialize() 228 237 { … … 242 251 SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con); 243 252 SLrScript_Command_Register_Void("ping", "pong!", "", ping); 244 } 253 254 SLrScript_Command_Register_Void("login", "logs into mariusnet", "username:string password:string", mnet_login); 255 } -
Daodan/MSVC/Flatline_Net.c
r584 r587 65 65 sockaddr_in client_address; 66 66 67 int NetUDPSocket_Create(uint16_t port )67 int NetUDPSocket_Create(uint16_t port, sockaddr_in* address) 68 68 { 69 69 int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 70 sockaddr_in address; 70 71 71 unsigned long nonBlocking = 1; 72 72 if (sock < 0) … … 77 77 78 78 79 memset(&client_address, 0, sizeof(sockaddr_in));80 address .sin_family = AF_INET;81 address .sin_addr.s_addr = htonl(INADDR_ANY);82 address .sin_port = htons(port);83 84 if (bind(sock, (sockaddr*) &address, sizeof(sockaddr_in)) < 0)79 // memset(&client_address, 0, sizeof(sockaddr_in)); 80 address->sin_family = AF_INET; 81 address->sin_addr.s_addr = htonl(INADDR_ANY); 82 address->sin_port = htons(port); 83 84 if (bind(sock, (sockaddr*)address, sizeof(sockaddr_in)) < 0) 85 85 { 86 86 DDrConsole_PrintF("could not bind port %d", port); … … 95 95 } 96 96 client_sock = sock; 97 client_address = address;98 97 return sock; 99 98 } 100 99 101 int NetTCPSocket_Create(uint16_t port )100 int NetTCPSocket_Create(uint16_t port, sockaddr_in* address) 102 101 { 103 102 int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 104 sockaddr_in address; 105 unsigned long nonBlocking = 1; 106 103 104 unsigned long nonBlocking = 0; 107 105 if (sock < 0) 108 106 { … … 112 110 113 111 114 memset(&client_address, 0, sizeof(sockaddr_in));115 address.sin_family = AF_INET;116 address.sin_addr.s_addr = htonl(INADDR_ANY);117 address.sin_port = htons(port);118 119 if (bind(sock, (sockaddr*) &address, sizeof(sockaddr_in)) < 0)112 // memset(&client_address, 0, sizeof(sockaddr_in)); 113 //address->sin_family = AF_INET; 114 //address->sin_addr.s_addr = INADDR_ANY; 115 //address->sin_port = htons(port); 116 /* 117 if (bind(sock, (sockaddr*)address, sizeof(sockaddr_in)) < 0) 120 118 { 121 119 DDrConsole_PrintF("could not bind port %d", port); … … 123 121 } 124 122 125 123 /* 126 124 if (ioctlsocket(sock, FIONBIO, &nonBlocking)) 127 125 { 128 126 DDrConsole_PrintF("failed to set non-blocking socket"); 129 127 return false; 130 } 131 client_sock = sock; 132 client_address = address; 128 }*/ 129 //client_sock = sock; 133 130 return sock; 134 131 } 135 136 132 137 133 void NetUDPSocket_Close(int socket) … … 144 140 //currently only protects against duplicate packets. 145 141 int addr_size; 146 #ifdef TRACK_PACKETS 142 int sent_bytes; 143 #if 0 //#ifdef TRACK_PACKETS 147 144 static uint32_t packet_index = 0; 148 145 packet_index = (packet_index + 1); … … 161 158 addr_size = sizeof(sockaddr_storage); 162 159 } 163 return sendto(socket, data, datalen, 0, address, addr_size); 160 sent_bytes = sendto(socket, data, datalen, 0, address, addr_size); 161 162 if(sent_bytes == SOCKET_ERROR) { 163 NetCatchError(); 164 } 165 166 return sent_bytes; 164 167 } 165 168 … … 182 185 return false; 183 186 } 184 } 185 /* 186 #ifdef TRACK_PACKETS 187 if(client_connected && !server_started) { 188 uint32_t index_mkr = ((flatline_packet*)(data))->packet_index; 189 //fancy way of checking if index_mkr is on one side of the max size of an int and last_packet is on the other 190 if( ((index_mkr - last_packet < 0x80000000) && (index_mkr > last_packet)) 191 //if it is, subtract half the size of an int from each. ^_^ 192 || ((index_mkr - 0x80000000) > (last_packet - 0x80000000) ) ) 193 { 194 return false; 195 } 196 else { 197 last_packet = index_mkr; 198 } 199 } 200 201 #endif 202 */ 203 187 } 204 188 *datalen = msg_size; 205 189 return true; 206 190 207 191 } 208 209 210 192 211 193 DWORD WINAPI StartServer(void* lol){ -
Daodan/MSVC/Flatline_Win32.c
r567 r587 1 1 #include "Flatline.h" 2 2 bool WSAStarted = 0; 3 3 bool NetPlatform_Initalize() 4 4 { 5 5 WSADATA wsaData; 6 7 if (WSAStartup(MAKEWORD(2, 2), &wsaData)) 6 if(!WSAStarted) 8 7 { 9 DDrConsole_PrintF("WSA initalization failed"); 10 return false; 8 if (WSAStartup(MAKEWORD(2, 2), &wsaData)) 9 { 10 DDrConsole_PrintF("WSA initalization failed"); 11 return false; 12 } 13 DDrConsole_PrintF("net started using WSA version %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion)); 11 14 } 12 DDrConsole_PrintF("net started using WSA version %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));13 15 return true; 14 16 }
Note:
See TracChangeset
for help on using the changeset viewer.