Changeset 588 for Daodan/MSVC
- Timestamp:
- Feb 11, 2011, 9:21:14 AM (14 years ago)
- Location:
- Daodan/MSVC
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/MSVC/Flatline.c
r587 r588 27 27 28 28 29 bool FLrServer_Run() 30 { 31 // Get the local hostname 32 char szHostName[255]; 33 struct hostent *host_entry; 34 gethostname(szHostName, 255); 35 36 host_entry=gethostbyname(szHostName); 37 DDrConsole_PrintF("Server started at %s...", inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list)); 38 return NetUDPServer_Listen(27777, FLrServer_PacketCallback); 39 } 29 40 30 41 31 short TRrAnimation_GetType(char* anim) -
Daodan/MSVC/Flatline_BSL.c
r587 r588 63 63 sprintf(message.data, "%s", args[0].value_str32); 64 64 NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)&message, 257); 65 } 66 else if(MsNet_Running) { 67 MSNet_SendChat( args[0].value_str32 ); 65 68 } 66 69 else { -
Daodan/MSVC/Flatline_Server.c
r586 r588 2 2 #include "Flatline_Server.h" 3 3 #include <Windows.h> 4 4 #include "PortForwardWrapper.h" 5 5 //I hereby apologize for the uglyness of the below code. 6 6 //It was never intended to be "final" code, much less shared with anyone … … 376 376 return true; 377 377 } 378 379 380 381 bool FLrServer_Run() 382 { 383 HRESULT ret; 384 PortMappingContainer_C PMC = 385 { 386 "", 387 "27777", 388 "27777", 389 "UDP", 390 "", 391 "", 392 "Flatline!" 393 }; 394 // Get the local hostname 395 char szHostName[255]; 396 struct hostent *host_entry; 397 gethostname(szHostName, 255); 398 399 host_entry=gethostbyname(szHostName); 400 401 strcpy( PMC.InternalClient, inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list) ); 402 ret = uPnP_Forward( &PMC ); 403 if(!ret) 404 { 405 DDrConsole_Print( "Port Forwarded" ); 406 } 407 else 408 { 409 LPSTR Message; 410 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, &ret,0,0,&Message,0,NULL); 411 DDrConsole_Print( Message ); 412 } 413 414 DDrConsole_PrintF("Server started at %s...", inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list)); 415 return NetUDPServer_Listen(27777, FLrServer_PacketCallback); 416 } -
Daodan/MSVC/Mariusnet.c
r587 r588 20 20 bool RoomListGotten = 0; 21 21 22 bool Are_We_Logged_In = 0; 23 24 RGBA blue = {0xFF, 0, 0, 0}; 22 bool MariusNet_LoggedIn = 0; 23 24 bool MsNet_Running = 0; 25 int Marius_Socket = -1; 26 int Room_Socket = -1; 27 sockaddr_in RoomAddr = {0}; 28 int PlayerID = 0; 29 /* 30 25 31 RGBA green = {0, 0xFF, 0, 0}; 26 32 RGBA red = {0, 0, 0xFF, 0}; 27 33 28 34 RGBA grey = {0x80,0x80,0x80,0x80}; 29 35 */ 36 extern RGBA red; 37 //extern RGBA blue; 38 RGBA blue = {0xFF, 0, 0, 0}; 39 RGBA cyan = {0xFF, 0xFF, 0, 0}; 40 RGBA white = {0xFF, 0xFF, 0xFF, 0}; 41 extern RGBA green; 42 extern RGBA grey; 30 43 int MariusNet_OutgoingPacketWrapper(int socket, const sockaddr* address, marius_packet* data, short datalen) 31 44 { … … 259 272 260 273 } 274 275 void MSNet_HandleChat( m_message* msg ) 276 { 277 //BGRA *cough* 278 /*RGBA chatcolor; 279 chatcolor.R = (msg->PrimaryColor.Red); 280 chatcolor.G = (msg->PrimaryColor.Green); 281 chatcolor.B = (msg->PrimaryColor.Blue); 282 chatcolor.A = 0;*/ 283 char Message[1024]; 284 int NameLen = sprintf_s( Message, 1024, "%s", msg->Message ) + 1; 285 sprintf_s( Message, 1024 - NameLen, "%s: %s", Message, msg->Message + NameLen ); 286 //DDrConsole_PrintColored( msg->Message, 0, chatcolor,white ); 287 DDrConsole_Print(Message); 288 } 289 290 void MSNet_SendChat( char* msg ) 291 { 292 marius_packet mPacket = {0}; 293 int len; 294 if(!MsNet_Running || !MariusNet_LoggedIn) return; 295 296 Initialize_MPacket(&mPacket, pt_ChatMessage); 297 298 299 mPacket.message.SecondaryColor.Red = mPacket.message.SecondaryColor.Flags = -1; 300 301 302 303 //mPacket.message.Message = 'Gumby'; 304 len = sprintf(mPacket.message.Message, "O %s", msg ); 305 mPacket.message.Message[1] = 0; 306 mPacket.message.SenderId = htonl(PlayerID); 307 //mPacket.message.TargetId = -1; 308 MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, (char*)&mPacket, 309 sizeof(marius_header) + sizeof(m_message) - (255 - len) ); 310 311 312 } 313 314 int MSNet_Cleanup() 315 { 316 if( Marius_Socket != -1) closesocket(Marius_Socket); 317 Marius_Socket = -1; 318 if( Room_Socket != -1) closesocket(Room_Socket); 319 Room_Socket = -1; 320 memset(RoomList, 0, sizeof(m_room) * 64 ); 321 DDrConsole_PrintF("The metaserver connection will now close." ); 322 MsNet_Running = 0; 323 MariusNet_LoggedIn = 0; 324 return 1; 325 } 326 327 void MSNet_HandleGameList( m_gameinfo* PacketGames, int PacketSize ) 328 { 329 m_gameinfo TempGameList[64] = {0}; 330 int i ; 331 for( i = 0; PacketSize > 0; i++ ) 332 { 333 int ThisSize = sizeof(m_gameinfo) + ntohs(PacketGames->len) - sizeof(m_gamedescription); 334 335 memcpy(TempGameList + i,PacketGames, sizeof(m_gameinfo) - 128); 336 337 sprintf_s( TempGameList[i].g.Buffer, 128, "%s", PacketGames->g.Buffer); 338 PacketSize -= ThisSize; 339 PacketGames = (m_gameinfo*)((char*)PacketGames + ThisSize); 340 341 } 342 //Do stuff with the games. 343 } 344 261 345 int MSNet_Room_Join( short Room, char* Key) 262 346 { … … 268 352 269 353 sockaddr_in SockAddr; 270 int Room_Socket = NetTCPSocket_Create(RoomList[Room].Port, &SockAddr);271 272 sockaddr_in RoomAddr = {0};273 354 RoomAddr.sin_port = RoomList[Room].Port; 274 355 RoomAddr.sin_family = AF_INET; 275 356 RoomAddr.sin_addr.S_un.S_addr = RoomList[Room].IPAddress; 276 357 277 358 Room_Socket = NetTCPSocket_Create(RoomList[Room].Port, &SockAddr); 278 359 279 360 DDrConsole_PrintF("Joining room %hi", Room); … … 282 363 { 283 364 DDrConsole_PrintF("Failed to initialize room socket!"); 365 return MSNet_Cleanup(); 284 366 } 285 367 … … 287 369 { 288 370 NetCatchError(); 289 return 1; 371 MariusNet_LoggedIn = 0; 372 return MSNet_Cleanup(); 290 373 } 291 374 … … 306 389 if(MariusNet_IncomingPacketWrapper(Room_Socket, incomingData, 1400, 0) == SOCKET_ERROR) 307 390 { 308 return 0;391 return MSNet_Cleanup(); 309 392 } 310 393 … … 313 396 //DDrConsole_PrintF("Login failed: %s", incomingPacket->login_denied.DenialMessage ); 314 397 MSNet_LoginError_Output(ntohl(incomingPacket->login_denied.code)); 315 return 0; 316 } 317 398 return MSNet_Cleanup(); 399 } 400 401 MariusNet_LoggedIn = 1; 402 403 /* 404 Initialize_MPacket(&mPacket, 104); 405 mPacket.newgame.g.maxplayers = -1; 406 mPacket.newgame.g.clientversion = htonl(0xc136e436); 407 mPacket.newgame.g.maxteams = -1; 408 //sprintf(mPacket.newgame.g.Buffer, "Oni!"); 409 memcpy(mPacket.newgame.g.Buffer, "Blam!\0This is Oni, bitch.\0", 50); 410 sent_bytes = MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, (char*)&mPacket, 411 sizeof(marius_header) + sizeof(m_announcegame) + 50); 412 */ 318 413 while(1) 319 414 { … … 326 421 case pt_RoomList: 327 422 case pt_PlayerInfo: 328 case pt_GameList:329 423 case pt_PlayerList: 330 424 //Do nothing for now 331 425 break; 426 case pt_GameList: 427 MSNet_HandleGameList( incomingPacket->gamelist.Games, 428 ntohl(incomingPacket->header.PacketSize) - sizeof(marius_header)); 429 break; 332 430 case pt_BlueBarMsg: 333 DDrConsole_PrintColored(incomingPacket->motd.Message, 0, blue, grey );431 DDrConsole_PrintColored(incomingPacket->motd.Message, 0, cyan, grey ); 334 432 break; 335 433 case pt_ChatMessage: 434 MSNet_HandleChat(&incomingPacket->message); 336 435 break; 337 436 case pt_KeepAlive: … … 351 450 { 352 451 int Port = 4156; 353 int Marius_Socket = -1;354 int PlayerID;452 453 355 454 char RoomToken[33] = {0}; 356 455 int i = 0; 357 456 358 457 359 458 360 459 sockaddr_in Marius_Addr = {0}; 361 362 if(Are_We_Logged_In) 460 if(MsNet_Running) 461 { 462 DDrConsole_PrintF("The metaserver handler is already running!"); 463 } 464 MsNet_Running = 1; 465 466 if(MariusNet_LoggedIn) 363 467 { 364 468 DDrConsole_PrintF("You're already logged in!"); 365 return 0;469 return MSNet_Cleanup(); 366 470 } 367 471 … … 371 475 if(MariusNet_Initialize()) 372 476 { 373 return 0;477 return MSNet_Cleanup(); 374 478 } 375 479 … … 398 502 { 399 503 NetCatchError(); 400 return 0;504 return MSNet_Cleanup(); 401 505 } 402 506 DDrConsole_PrintF("Sending Player Info..."); … … 412 516 if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR) 413 517 { 414 return 0;518 return MSNet_Cleanup(); 415 519 } 416 520 … … 450 554 if(!NetUDPSocket_Recieve(Marius_Socket, (sockaddr*)&Marius_Addr,incomingData, &incomingLength)) 451 555 { 452 return 0;556 return MSNet_Cleanup(); 453 557 } 454 558 DDrConsole_PrintF("Password ACK!"); … … 465 569 if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR) 466 570 { 467 return 0;571 return MSNet_Cleanup(); 468 572 } 469 573 } … … 482 586 //DDrConsole_PrintF("Login failed: %s", incomingPacket->login_denied.DenialMessage ); 483 587 MSNet_LoginError_Output(ntohl(incomingPacket->login_denied.code)); 484 return 0;588 return MSNet_Cleanup(); 485 589 } 486 590 else 487 591 { 488 DDrConsole_PrintF("Something went wrong! Disconnecting from Mariusnet"); 489 return 0; 592 return MSNet_Cleanup(); 490 593 } 491 594 … … 495 598 if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR) 496 599 { 497 return 0;600 return MSNet_Cleanup(); 498 601 } 499 602 if(ntohs(incomingPacket->header.PacketId)== pt_RoomList) … … 512 615 { 513 616 DDrConsole_PrintF("Invalid packet type %hi", ntohs(incomingPacket->header.PacketId)); 514 return 0;617 return MSNet_Cleanup(); 515 618 } 516 619 } -
Daodan/MSVC/Mariusnet_Defs.h
r587 r588 167 167 typedef struct 168 168 { 169 170 ColorStuff : TColorInfo;169 m_colour PrimaryColor; 170 m_colour SecondaryColor; 171 171 int SenderId; 172 172 int TargetId; 173 173 char Message[256]; 174 } 175 176 174 } m_message; 175 176 typedef struct 177 { 178 short unknown16; 179 short type; 180 int options; 181 int timelimit; 182 int checksum; 183 short difficulty; 184 short maxplayers; 185 short teamrandomseed; 186 short maxteams; //-1 187 int planningtime; 188 int unusedint; 189 int unusedint_2; 190 short unknown16_2; 191 short pluginflag; 192 char pluginlist[512]; 193 int clientversion;//0xc136e436 194 int unknownint; 195 short status; 196 short numplayers; 197 char action; 198 char pad[3]; 199 char Buffer[128]; 200 } m_gamedescription; 201 202 typedef struct 203 { 204 short port; 205 short zero; 206 m_gamedescription g; 207 } m_announcegame; 208 209 typedef struct 210 { 211 unsigned int gameID; 212 unsigned int ipAddress; 213 unsigned short port; 214 unsigned char verb; 215 unsigned char gameEnable; 216 unsigned int timeRemaining; 217 unsigned int hostPlayerID; 218 unsigned short len; 219 int unused1; 220 int unused2; 221 short pad; 222 m_gamedescription g; 223 } m_gameinfo; 224 225 typedef struct 226 { 227 m_gameinfo Games[]; 228 } m_gamelist; 177 229 typedef struct 178 230 { … … 190 242 m_player_info player_info; 191 243 m_motd motd; 244 m_message message; 245 m_announcegame newgame; 246 m_gamelist gamelist; 192 247 }; 193 248 } marius_packet; -
Daodan/MSVC/Mariusnet_Public.h
r587 r588 1 extern bool MsNet_Running; 2 1 3 bool MSNet_Login(char* username, char* password); 4 void MSNet_SendChat( char* msg );
Note:
See TracChangeset
for help on using the changeset viewer.