| 3 |
|
#include "bool.h" |
| 4 |
|
#include "Flatline_Net.h" |
| 5 |
|
#include "Flatline_Win32.h" |
| 6 |
+ |
#include "Flatline_Client.h" |
| 7 |
|
#include "Mariusnet_Defs.h" |
| 8 |
|
#include "Daodan_Console.h" |
| 9 |
+ |
#include "Oni_Symbols.h" |
| 10 |
|
#include <stdio.h> |
| 11 |
|
#include <inaddr.h> |
| 12 |
|
#pragma comment(lib, "wininet.lib") |
| 13 |
|
|
| 14 |
|
|
| 13 |
– |
typedef struct hostent hostent ; |
| 14 |
– |
typedef struct in_addr in_addr; |
| 15 |
– |
|
| 15 |
|
char MariusLogin[32]={0}; |
| 16 |
|
unsigned char MariusPassword[16]={0}; |
| 17 |
|
|
| 25 |
|
int Room_Socket = -1; |
| 26 |
|
sockaddr_in RoomAddr = {0}; |
| 27 |
|
int PlayerID = 0; |
| 28 |
+ |
|
| 29 |
+ |
m_gameinfo StaticGameList[64] = {0}; |
| 30 |
+ |
enum |
| 31 |
+ |
{ |
| 32 |
+ |
glAddGame, |
| 33 |
+ |
glRemoveGame, |
| 34 |
+ |
glUpdateGame, |
| 35 |
+ |
}; |
| 36 |
+ |
|
| 37 |
|
/* |
| 38 |
|
|
| 39 |
|
RGBA green = {0, 0xFF, 0, 0}; |
| 48 |
|
RGBA white = {0xFF, 0xFF, 0xFF, 0}; |
| 49 |
|
extern RGBA green; |
| 50 |
|
extern RGBA grey; |
| 51 |
+ |
|
| 52 |
+ |
typedef struct |
| 53 |
+ |
{ |
| 54 |
+ |
uint16_t x; |
| 55 |
+ |
uint16_t y; |
| 56 |
+ |
|
| 57 |
+ |
} IMtPoint2D; |
| 58 |
+ |
void* DrawInstance = 0; |
| 59 |
+ |
void MSNet_DrawGames() |
| 60 |
+ |
{ |
| 61 |
+ |
|
| 62 |
+ |
if(!DrawInstance){ |
| 63 |
+ |
void* TSFFTahoma; |
| 64 |
+ |
TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma); |
| 65 |
+ |
TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &DrawInstance); |
| 66 |
+ |
} |
| 67 |
+ |
if(DrawInstance){ |
| 68 |
+ |
const int white = 0x00FFFFFF; |
| 69 |
+ |
const int green = 0x0000FF00; |
| 70 |
+ |
const int red = 0x00FF0000; |
| 71 |
+ |
const int blue = 0x000000FF; |
| 72 |
+ |
int i; |
| 73 |
+ |
char DrawString[255]; |
| 74 |
+ |
const int LineHeight = 15; |
| 75 |
+ |
IMtPoint2D StartLocation = {500, 20}; |
| 76 |
+ |
IMtPoint2D DrawLocation = StartLocation; |
| 77 |
+ |
TSrContext_SetShade(DrawInstance, white); |
| 78 |
+ |
TSrContext_DrawText(DrawInstance, "Mariusnet Games:", 255, 0, &DrawLocation); |
| 79 |
+ |
TSrContext_SetShade(DrawInstance, white); |
| 80 |
+ |
DrawLocation.y += LineHeight; |
| 81 |
+ |
|
| 82 |
+ |
for(i = 0; i < 64; i++) |
| 83 |
+ |
{ |
| 84 |
+ |
|
| 85 |
+ |
if(StaticGameList[i].gameID) |
| 86 |
+ |
{ |
| 87 |
+ |
DrawLocation.x = StartLocation.x - 10; |
| 88 |
+ |
sprintf(DrawString, "%i.", i ); |
| 89 |
+ |
TSrContext_DrawText(DrawInstance, DrawString, 255, 0, &DrawLocation); |
| 90 |
+ |
DrawLocation.x += 20; |
| 91 |
+ |
TSrContext_DrawText(DrawInstance, StaticGameList[i].g.Buffer, 255, 0, &DrawLocation); |
| 92 |
+ |
DrawLocation.y += LineHeight; |
| 93 |
+ |
} |
| 94 |
+ |
} |
| 95 |
+ |
|
| 96 |
+ |
} |
| 97 |
+ |
} |
| 98 |
+ |
|
| 99 |
+ |
|
| 100 |
|
int MariusNet_OutgoingPacketWrapper(int socket, const sockaddr* address, marius_packet* data, short datalen) |
| 101 |
|
{ |
| 102 |
|
data->header.PacketSize = htonl(datalen); |
| 349 |
|
marius_packet mPacket = {0}; |
| 350 |
|
int len; |
| 351 |
|
if(!MsNet_Running || !MariusNet_LoggedIn) return; |
| 352 |
< |
|
| 352 |
> |
|
| 353 |
|
Initialize_MPacket(&mPacket, pt_ChatMessage); |
| 354 |
|
|
| 355 |
|
|
| 363 |
|
mPacket.message.SenderId = htonl(PlayerID); |
| 364 |
|
//mPacket.message.TargetId = -1; |
| 365 |
|
MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, (char*)&mPacket, |
| 366 |
< |
sizeof(marius_header) + sizeof(m_message) - (255 - len) ); |
| 366 |
> |
sizeof(marius_header) + sizeof(m_message) - (255 - len) ); |
| 367 |
> |
|
| 368 |
|
|
| 369 |
+ |
} |
| 370 |
+ |
|
| 371 |
+ |
void MSNet_RoomExit() |
| 372 |
+ |
{ |
| 373 |
+ |
if(MariusNet_LoggedIn) |
| 374 |
+ |
{ |
| 375 |
+ |
if( Room_Socket != -1) closesocket(Room_Socket); |
| 376 |
+ |
memset(StaticGameList, 0, sizeof(m_gameinfo) * 64); |
| 377 |
+ |
MsNet_Running = 0; |
| 378 |
+ |
MariusNet_LoggedIn = 0; |
| 379 |
|
|
| 380 |
+ |
} |
| 381 |
+ |
return; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
+ |
|
| 385 |
|
int MSNet_Cleanup() |
| 386 |
|
{ |
| 387 |
|
if( Marius_Socket != -1) closesocket(Marius_Socket); |
| 389 |
|
if( Room_Socket != -1) closesocket(Room_Socket); |
| 390 |
|
Room_Socket = -1; |
| 391 |
|
memset(RoomList, 0, sizeof(m_room) * 64 ); |
| 392 |
+ |
memset(StaticGameList, 0, sizeof(m_gameinfo) * 64); |
| 393 |
|
DDrConsole_PrintF("The metaserver connection will now close." ); |
| 394 |
|
MsNet_Running = 0; |
| 395 |
|
MariusNet_LoggedIn = 0; |
| 396 |
|
return 1; |
| 397 |
|
} |
| 398 |
|
|
| 399 |
+ |
|
| 400 |
+ |
|
| 401 |
|
void MSNet_HandleGameList( m_gameinfo* PacketGames, int PacketSize ) |
| 402 |
|
{ |
| 403 |
|
m_gameinfo TempGameList[64] = {0}; |
| 404 |
< |
int i ; |
| 404 |
> |
int i, k; |
| 405 |
|
for( i = 0; PacketSize > 0; i++ ) |
| 406 |
|
{ |
| 407 |
|
int ThisSize = sizeof(m_gameinfo) + ntohs(PacketGames->len) - sizeof(m_gamedescription); |
| 413 |
|
PacketGames = (m_gameinfo*)((char*)PacketGames + ThisSize); |
| 414 |
|
|
| 415 |
|
} |
| 416 |
+ |
for( i = 0; TempGameList[i].gameID; i++) |
| 417 |
+ |
{ |
| 418 |
+ |
int DesiredID = 0; |
| 419 |
+ |
switch(TempGameList[i].verb) |
| 420 |
+ |
{ |
| 421 |
+ |
case(glRemoveGame): |
| 422 |
+ |
//Remove game from list |
| 423 |
+ |
DDrConsole_PrintF("%s has ended", TempGameList[i].g.Buffer); |
| 424 |
+ |
for(k = 0; k < 64; k++) |
| 425 |
+ |
{ |
| 426 |
+ |
if(TempGameList[i].gameID == StaticGameList[k].gameID) |
| 427 |
+ |
{ |
| 428 |
+ |
memset(StaticGameList + k, 0, sizeof(m_gameinfo) ); |
| 429 |
+ |
break; |
| 430 |
+ |
} |
| 431 |
+ |
|
| 432 |
+ |
} |
| 433 |
+ |
break; |
| 434 |
+ |
|
| 435 |
+ |
case(glAddGame): |
| 436 |
+ |
//Add game to list |
| 437 |
+ |
DDrConsole_PrintF("%s has started", TempGameList[i].g.Buffer); |
| 438 |
+ |
case(glUpdateGame): |
| 439 |
+ |
//Update list |
| 440 |
+ |
|
| 441 |
+ |
//If updating, look for the game to update, otherwise look for empty |
| 442 |
+ |
if(TempGameList[i].verb) DesiredID = TempGameList[i].gameID; |
| 443 |
+ |
for(k = 0; k < 64; k++) |
| 444 |
+ |
{ |
| 445 |
+ |
if(DesiredID == StaticGameList[k].gameID) |
| 446 |
+ |
{ |
| 447 |
+ |
memcpy(StaticGameList + k, TempGameList + i, sizeof(m_gameinfo) ); |
| 448 |
+ |
break; |
| 449 |
+ |
} |
| 450 |
+ |
|
| 451 |
+ |
} |
| 452 |
+ |
break; |
| 453 |
+ |
break; |
| 454 |
+ |
} |
| 455 |
+ |
//TempGame |
| 456 |
+ |
} |
| 457 |
|
//Do stuff with the games. |
| 458 |
|
} |
| 459 |
|
|
| 460 |
+ |
int MSNet_CreateGame( m_announcegame* Game ) |
| 461 |
+ |
{ |
| 462 |
+ |
marius_packet mPacket; |
| 463 |
+ |
Initialize_MPacket(&mPacket, 104); |
| 464 |
+ |
mPacket.newgame = *Game; |
| 465 |
+ |
MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, (char*)&mPacket, |
| 466 |
+ |
sizeof(marius_header) + sizeof(m_announcegame)); |
| 467 |
+ |
} |
| 468 |
+ |
|
| 469 |
+ |
/* |
| 470 |
+ |
Initialize_MPacket(&mPacket, 104); |
| 471 |
+ |
mPacket.newgame.g.maxplayers = -1; |
| 472 |
+ |
mPacket.newgame.g.clientversion = htonl(0xc136e436); |
| 473 |
+ |
mPacket.newgame.g.maxteams = -1; |
| 474 |
+ |
//sprintf(mPacket.newgame.g.Buffer, "Oni!"); |
| 475 |
+ |
memcpy(mPacket.newgame.g.Buffer, "Blam!\0This is Oni, bitch.\0", 50); |
| 476 |
+ |
sent_bytes = MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, (char*)&mPacket, |
| 477 |
+ |
sizeof(marius_header) + sizeof(m_announcegame) + 50); |
| 478 |
+ |
*/ |
| 479 |
+ |
|
| 480 |
|
int MSNet_Room_Join( short Room, char* Key) |
| 481 |
|
{ |
| 482 |
|
marius_packet mPacket = {0}; |
| 535 |
|
|
| 536 |
|
MariusNet_LoggedIn = 1; |
| 537 |
|
|
| 538 |
< |
/* |
| 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 |
< |
*/ |
| 538 |
> |
|
| 539 |
|
while(1) |
| 540 |
|
{ |
| 541 |
|
if(MariusNet_IncomingPacketWrapper(Room_Socket, incomingData, 1400, 0) == SOCKET_ERROR) |
| 706 |
|
//so it always zero terminates. |
| 707 |
|
memcpy(RoomToken, incomingPacket->login_success.Token, 32); |
| 708 |
|
DDrConsole_PrintF("Logged into Mariusnet!"); |
| 709 |
+ |
strcpy_s( player_name, 32, MariusLogin ); |
| 710 |
|
} |
| 711 |
|
else if(ntohs(incomingPacket->header.PacketId)== pt_LoginInfo) |
| 712 |
|
{ |
| 760 |
|
|
| 761 |
|
closesocket(Marius_Socket); |
| 762 |
|
|
| 763 |
< |
MSNet_Room_Join( 1, RoomToken ); |
| 763 |
> |
MSNet_Room_Join( 0, RoomToken ); |
| 764 |
|
|
| 765 |
|
|
| 766 |
|
} |
| 767 |
|
return 0; |
| 768 |
|
} |
| 769 |
+ |
|
| 770 |
+ |
uint16_t ONICALL mnet_joingame(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 771 |
+ |
{ |
| 772 |
+ |
int index = args[0].value_int32; |
| 773 |
+ |
if(index >= 0) |
| 774 |
+ |
{ |
| 775 |
+ |
FLcConnect(StaticGameList[index].ipAddress, StaticGameList[index].port); |
| 776 |
+ |
} |
| 777 |
+ |
return 0; |
| 778 |
+ |
} |
| 779 |
|
|
| 780 |
|
bool MSNet_Login(char* username, char* password) |
| 781 |
|
{ |