| 19 |
|
m_room RoomList[64] = {0}; |
| 20 |
|
bool RoomListGotten = 0; |
| 21 |
|
|
| 22 |
< |
bool Are_We_Logged_In = 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 |
|
|
| 24 |
– |
RGBA blue = {0xFF, 0, 0, 0}; |
| 31 |
|
RGBA green = {0, 0xFF, 0, 0}; |
| 32 |
|
RGBA red = {0, 0, 0xFF, 0}; |
| 33 |
|
|
| 34 |
|
RGBA grey = {0x80,0x80,0x80,0x80}; |
| 35 |
< |
|
| 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; |
| 43 |
|
int MariusNet_OutgoingPacketWrapper(int socket, const sockaddr* address, marius_packet* data, short datalen) |
| 44 |
|
{ |
| 45 |
|
data->header.PacketSize = htonl(datalen); |
| 194 |
|
"Braindead Simple", |
| 195 |
|
}; |
| 196 |
|
|
| 197 |
< |
enum { |
| 198 |
< |
SyntaxError, |
| 199 |
< |
GamesNotAllowed, |
| 200 |
< |
InvalidVersion, |
| 201 |
< |
BadUserOrPassword, |
| 202 |
< |
UserNotLoggedIn, |
| 203 |
< |
BadMetaserverVersion, |
| 204 |
< |
UserAlreadyLoggedIn, |
| 205 |
< |
UnknownGameType, |
| 206 |
< |
LoginSuccessful, |
| 207 |
< |
LogoutSuccessful, |
| 208 |
< |
PlayerNotInRoom, |
| 209 |
< |
GameAlreadyExists, |
| 210 |
< |
AccountAlreadyLoggedIn, |
| 211 |
< |
RoomFull, |
| 212 |
< |
AccountLocked, |
| 213 |
< |
NotSupported |
| 197 |
> |
enum { |
| 198 |
> |
SyntaxError, |
| 199 |
> |
GamesNotAllowed, |
| 200 |
> |
InvalidVersion, |
| 201 |
> |
BadUserOrPassword, |
| 202 |
> |
UserNotLoggedIn, |
| 203 |
> |
BadMetaserverVersion, |
| 204 |
> |
UserAlreadyLoggedIn, |
| 205 |
> |
UnknownGameType, |
| 206 |
> |
LoginSuccessful, |
| 207 |
> |
LogoutSuccessful, |
| 208 |
> |
PlayerNotInRoom, |
| 209 |
> |
GameAlreadyExists, |
| 210 |
> |
AccountAlreadyLoggedIn, |
| 211 |
> |
RoomFull, |
| 212 |
> |
AccountLocked, |
| 213 |
> |
NotSupported |
| 214 |
|
}; |
| 215 |
|
|
| 216 |
< |
static const char* sRoomNames[] = { |
| 217 |
< |
"Crows Bridge", |
| 218 |
< |
"Otter Ferry", |
| 219 |
< |
"White Falls", |
| 220 |
< |
"Silvermines", |
| 221 |
< |
"Shoal", |
| 222 |
< |
"Madrigal", |
| 223 |
< |
"Tyr", |
| 224 |
< |
"Ash", |
| 225 |
< |
"Scales", |
| 226 |
< |
"Covenant", |
| 227 |
< |
"Muirthemne", |
| 228 |
< |
"Seven Gates", |
| 229 |
< |
"Bagrada", |
| 230 |
< |
"The Barrier", |
| 231 |
< |
"Forest Heart", |
| 232 |
< |
"The Ermine", |
| 233 |
< |
"The Dire Marsh", |
| 234 |
< |
"The Highlands", |
| 235 |
< |
"The Drowned Kingdom", |
| 236 |
< |
"The Great Devoid", |
| 237 |
< |
"Shiver", |
| 238 |
< |
"The Caterthuns", |
| 239 |
< |
"Soulblighter", |
| 240 |
< |
"Balor", |
| 241 |
< |
"Sons of Myrgard", |
| 242 |
< |
"Heart of the Stone", |
| 243 |
< |
"Arrival", |
| 244 |
< |
"Ingue Ferroque", |
| 245 |
< |
"Vimy Ridge", |
| 246 |
< |
"Stilwell Road" |
| 216 |
> |
static const char* sRoomNames[] = { |
| 217 |
> |
"Crows Bridge", |
| 218 |
> |
"Otter Ferry", |
| 219 |
> |
"White Falls", |
| 220 |
> |
"Silvermines", |
| 221 |
> |
"Shoal", |
| 222 |
> |
"Madrigal", |
| 223 |
> |
"Tyr", |
| 224 |
> |
"Ash", |
| 225 |
> |
"Scales", |
| 226 |
> |
"Covenant", |
| 227 |
> |
"Muirthemne", |
| 228 |
> |
"Seven Gates", |
| 229 |
> |
"Bagrada", |
| 230 |
> |
"The Barrier", |
| 231 |
> |
"Forest Heart", |
| 232 |
> |
"The Ermine", |
| 233 |
> |
"The Dire Marsh", |
| 234 |
> |
"The Highlands", |
| 235 |
> |
"The Drowned Kingdom", |
| 236 |
> |
"The Great Devoid", |
| 237 |
> |
"Shiver", |
| 238 |
> |
"The Caterthuns", |
| 239 |
> |
"Soulblighter", |
| 240 |
> |
"Balor", |
| 241 |
> |
"Sons of Myrgard", |
| 242 |
> |
"Heart of the Stone", |
| 243 |
> |
"Arrival", |
| 244 |
> |
"Ingue Ferroque", |
| 245 |
> |
"Vimy Ridge", |
| 246 |
> |
"Stilwell Road" |
| 247 |
|
}; |
| 248 |
|
void MSNet_LoginError_Output( int code ) |
| 249 |
|
{ |
| 250 |
|
switch(code) |
| 251 |
|
{ |
| 252 |
< |
case(BadUserOrPassword): |
| 253 |
< |
DDrConsole_PrintF( "Login denied: bad username or password." ); |
| 254 |
< |
break; |
| 255 |
< |
case(UserAlreadyLoggedIn): |
| 256 |
< |
DDrConsole_PrintF( "Login denied: that user is already logged in."); |
| 257 |
< |
break; |
| 258 |
< |
case(AccountAlreadyLoggedIn): |
| 259 |
< |
DDrConsole_PrintF( "Login denied: that account is already logged in."); |
| 260 |
< |
break; |
| 261 |
< |
case(RoomFull): |
| 262 |
< |
DDrConsole_PrintF( "Login denied: room is full!?"); |
| 263 |
< |
break; |
| 264 |
< |
case(AccountLocked): |
| 265 |
< |
DDrConsole_PrintF( "Login denied: your account is locked."); |
| 266 |
< |
break; |
| 267 |
< |
default: |
| 268 |
< |
DDrConsole_PrintF("There was a problem connecting to the server" |
| 269 |
< |
"that tracks Internet games. Please try again later."); |
| 270 |
< |
break; |
| 252 |
> |
case(BadUserOrPassword): |
| 253 |
> |
DDrConsole_PrintF( "Login denied: bad username or password." ); |
| 254 |
> |
break; |
| 255 |
> |
case(UserAlreadyLoggedIn): |
| 256 |
> |
DDrConsole_PrintF( "Login denied: that user is already logged in."); |
| 257 |
> |
break; |
| 258 |
> |
case(AccountAlreadyLoggedIn): |
| 259 |
> |
DDrConsole_PrintF( "Login denied: that account is already logged in."); |
| 260 |
> |
break; |
| 261 |
> |
case(RoomFull): |
| 262 |
> |
DDrConsole_PrintF( "Login denied: room is full!?"); |
| 263 |
> |
break; |
| 264 |
> |
case(AccountLocked): |
| 265 |
> |
DDrConsole_PrintF( "Login denied: your account is locked."); |
| 266 |
> |
break; |
| 267 |
> |
default: |
| 268 |
> |
DDrConsole_PrintF("There was a problem connecting to the server" |
| 269 |
> |
"that tracks Internet games. Please try again later."); |
| 270 |
> |
break; |
| 271 |
|
} |
| 272 |
|
|
| 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 |
+ |
|
| 345 |
|
int MSNet_Room_Join( short Room, char* Key) |
| 346 |
|
{ |
| 347 |
|
marius_packet mPacket = {0}; |
| 351 |
|
int sent_bytes = 0; |
| 352 |
|
|
| 353 |
|
sockaddr_in SockAddr; |
| 270 |
– |
int Room_Socket = NetTCPSocket_Create(RoomList[Room].Port, &SockAddr); |
| 271 |
– |
|
| 272 |
– |
sockaddr_in RoomAddr = {0}; |
| 354 |
|
RoomAddr.sin_port = RoomList[Room].Port; |
| 355 |
|
RoomAddr.sin_family = AF_INET; |
| 356 |
|
RoomAddr.sin_addr.S_un.S_addr = RoomList[Room].IPAddress; |
| 357 |
|
|
| 358 |
< |
|
| 358 |
> |
Room_Socket = NetTCPSocket_Create(RoomList[Room].Port, &SockAddr); |
| 359 |
|
|
| 360 |
|
DDrConsole_PrintF("Joining room %hi", Room); |
| 361 |
|
|
| 362 |
|
if(Room_Socket == -1) |
| 363 |
|
{ |
| 364 |
|
DDrConsole_PrintF("Failed to initialize room socket!"); |
| 365 |
+ |
return MSNet_Cleanup(); |
| 366 |
|
} |
| 367 |
|
|
| 368 |
|
if(connect( Room_Socket, (sockaddr *)&RoomAddr, sizeof(sockaddr_in))) |
| 369 |
|
{ |
| 370 |
|
NetCatchError(); |
| 371 |
< |
return 1; |
| 371 |
> |
MariusNet_LoggedIn = 0; |
| 372 |
> |
return MSNet_Cleanup(); |
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
Initialize_MPacket(&mPacket, pt_ChatRoomLogin); |
| 388 |
|
|
| 389 |
|
if(MariusNet_IncomingPacketWrapper(Room_Socket, incomingData, 1400, 0) == SOCKET_ERROR) |
| 390 |
|
{ |
| 391 |
< |
return 0; |
| 391 |
> |
return MSNet_Cleanup(); |
| 392 |
|
} |
| 393 |
|
|
| 394 |
|
if(ntohs(incomingPacket->header.PacketId)== pt_LoginInfo) |
| 395 |
|
{ |
| 396 |
|
//DDrConsole_PrintF("Login failed: %s", incomingPacket->login_denied.DenialMessage ); |
| 397 |
|
MSNet_LoginError_Output(ntohl(incomingPacket->login_denied.code)); |
| 398 |
< |
return 0; |
| 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 |
+ |
*/ |
| 413 |
|
while(1) |
| 414 |
|
{ |
| 415 |
|
if(MariusNet_IncomingPacketWrapper(Room_Socket, incomingData, 1400, 0) == SOCKET_ERROR) |
| 420 |
|
{ |
| 421 |
|
case pt_RoomList: |
| 422 |
|
case pt_PlayerInfo: |
| 328 |
– |
case pt_GameList: |
| 423 |
|
case pt_PlayerList: |
| 424 |
|
//Do nothing for now |
| 425 |
|
break; |
| 426 |
+ |
case pt_GameList: |
| 427 |
+ |
MSNet_HandleGameList( incomingPacket->gamelist.Games, |
| 428 |
+ |
ntohl(incomingPacket->header.PacketSize) - sizeof(marius_header)); |
| 429 |
+ |
break; |
| 430 |
|
case pt_BlueBarMsg: |
| 431 |
< |
DDrConsole_PrintColored(incomingPacket->motd.Message, 0, blue, grey ); |
| 431 |
> |
DDrConsole_PrintColored(incomingPacket->motd.Message, 0, cyan, grey ); |
| 432 |
|
break; |
| 433 |
|
case pt_ChatMessage: |
| 434 |
+ |
MSNet_HandleChat(&incomingPacket->message); |
| 435 |
|
break; |
| 436 |
|
case pt_KeepAlive: |
| 437 |
|
MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, incomingData, |
| 449 |
|
DWORD WINAPI MSNet_Handler(void* unused) |
| 450 |
|
{ |
| 451 |
|
int Port = 4156; |
| 452 |
< |
int Marius_Socket = -1; |
| 453 |
< |
int PlayerID; |
| 452 |
> |
|
| 453 |
> |
|
| 454 |
|
char RoomToken[33] = {0}; |
| 455 |
|
int i = 0; |
| 357 |
– |
|
| 456 |
|
|
| 457 |
|
|
| 360 |
– |
sockaddr_in Marius_Addr = {0}; |
| 458 |
|
|
| 459 |
< |
if(Are_We_Logged_In) |
| 459 |
> |
sockaddr_in Marius_Addr = {0}; |
| 460 |
> |
if(MsNet_Running) |
| 461 |
> |
{ |
| 462 |
> |
DDrConsole_PrintF("The metaserver handler is already running!"); |
| 463 |
> |
} |
| 464 |
> |
MsNet_Running = 1; |
| 465 |
> |
|
| 466 |
> |
if(MariusNet_LoggedIn) |
| 467 |
|
{ |
| 468 |
|
DDrConsole_PrintF("You're already logged in!"); |
| 469 |
< |
return 0; |
| 469 |
> |
return MSNet_Cleanup(); |
| 470 |
|
} |
| 471 |
|
|
| 472 |
|
NetPlatform_Initalize(); |
| 474 |
|
|
| 475 |
|
if(MariusNet_Initialize()) |
| 476 |
|
{ |
| 477 |
< |
return 0; |
| 477 |
> |
return MSNet_Cleanup(); |
| 478 |
|
} |
| 479 |
|
|
| 480 |
|
//Horribly set up. |
| 501 |
|
if(connect( Marius_Socket, &Marius_Server, sizeof(sockaddr_in))) |
| 502 |
|
{ |
| 503 |
|
NetCatchError(); |
| 504 |
< |
return 0; |
| 504 |
> |
return MSNet_Cleanup(); |
| 505 |
|
} |
| 506 |
|
DDrConsole_PrintF("Sending Player Info..."); |
| 507 |
|
sent_bytes = MariusNet_OutgoingPacketWrapper(Marius_Socket, (sockaddr*)&Marius_Server, (char*)&mPacket, |
| 515 |
|
*/ |
| 516 |
|
if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR) |
| 517 |
|
{ |
| 518 |
< |
return 0; |
| 518 |
> |
return MSNet_Cleanup(); |
| 519 |
|
} |
| 520 |
|
|
| 521 |
|
if(ntohs(incomingPacket->header.PacketId)== pt_EncryptionKey) |
| 553 |
|
|
| 554 |
|
if(!NetUDPSocket_Recieve(Marius_Socket, (sockaddr*)&Marius_Addr,incomingData, &incomingLength)) |
| 555 |
|
{ |
| 556 |
< |
return 0; |
| 556 |
> |
return MSNet_Cleanup(); |
| 557 |
|
} |
| 558 |
|
DDrConsole_PrintF("Password ACK!"); |
| 559 |
|
if(ntohs(incomingPacket->header.PacketId)== pt_PasswordAck) |
| 568 |
|
|
| 569 |
|
if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR) |
| 570 |
|
{ |
| 571 |
< |
return 0; |
| 571 |
> |
return MSNet_Cleanup(); |
| 572 |
|
} |
| 573 |
|
} |
| 574 |
|
} |
| 585 |
|
{ |
| 586 |
|
//DDrConsole_PrintF("Login failed: %s", incomingPacket->login_denied.DenialMessage ); |
| 587 |
|
MSNet_LoginError_Output(ntohl(incomingPacket->login_denied.code)); |
| 588 |
< |
return 0; |
| 588 |
> |
return MSNet_Cleanup(); |
| 589 |
|
} |
| 590 |
|
else |
| 591 |
|
{ |
| 592 |
< |
DDrConsole_PrintF("Something went wrong! Disconnecting from Mariusnet"); |
| 489 |
< |
return 0; |
| 592 |
> |
return MSNet_Cleanup(); |
| 593 |
|
} |
| 594 |
|
|
| 595 |
|
|
| 597 |
|
{ |
| 598 |
|
if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR) |
| 599 |
|
{ |
| 600 |
< |
return 0; |
| 600 |
> |
return MSNet_Cleanup(); |
| 601 |
|
} |
| 602 |
|
if(ntohs(incomingPacket->header.PacketId)== pt_RoomList) |
| 603 |
|
{ |
| 614 |
|
else |
| 615 |
|
{ |
| 616 |
|
DDrConsole_PrintF("Invalid packet type %hi", ntohs(incomingPacket->header.PacketId)); |
| 617 |
< |
return 0; |
| 617 |
> |
return MSNet_Cleanup(); |
| 618 |
|
} |
| 619 |
|
} |
| 620 |
|
while(PacketCached || !RoomListGotten); |