Advertisement
Guest User

Untitled

a guest
May 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.27 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <conio.h>
  3. #include <map>
  4. //90.227.223.129
  5.  
  6. void error_handler( const char *msg, bool is_fatal = false );
  7.  
  8. // session vars - needed to login to game server
  9. unsigned char ls_sessionKey1[8] = {0,0,0,0, 0,0,0,0};
  10. unsigned char ls_sessionKey2[8] = {0,0,0,0, 0,0,0,0};
  11.  
  12. // session vars - needed to parse game packets
  13. L2Game_KeyPacket *p_game_key = NULL;
  14.  
  15. unsigned char p_initialGameKey[8] = {0,0,0,0, 0,0,0,0};
  16.  
  17. // Ready / Recv params
  18. int readyRead = 0, readyWrite = 0, recvBytes = 0;
  19.  
  20. // Game Server network stuff
  21. SOCKET pGameSocket=NULL;
  22.  
  23. unsigned char *GameNetBuffer = 0;
  24. unsigned int GameRcvdLen = 0, GameSentLen = 0;
  25.  
  26. // Timer Stuff
  27. long timerResolutionMsec = 10;
  28. DWORD lastWorldTickTime;
  29.  
  30. // Std map that include all world objects for your client.
  31. std::map< int, L2Player* > mGameWorldObjects;
  32.  
  33. void ProcessLoginState( const char *l2login, const char *l2pass )
  34. {
  35. SOCKET s = L2PNet_TCPsocket_create( true ); // create async TCP socket
  36. if( s == INVALID_SOCKET )
  37. {
  38. error_handler( "socket creation" );
  39. return;
  40. }
  41. printf( "Socket created to Auth Server...\n" );
  42.  
  43. // start connecting
  44. printf( "Connecting to Auth Server... " );
  45. L2PNet_connect( s, "90.227.223.129", 2106 );
  46. // network vars
  47. int nTries;
  48. nTries = 10;
  49. recvBytes = 0;
  50. while( nTries>0 && recvBytes==0 )
  51. {
  52. printf( "." );
  53. recvBytes = L2PNet_select( s, L2PNET_SELECT_WRITE, 1000, &readyRead, &readyWrite );
  54. if( recvBytes == 1 ) break;
  55. nTries--;
  56. }
  57. if( recvBytes == 0 )
  58. {
  59. error_handler( "Connect failed!" );
  60. return;
  61. }
  62. printf( "Connected to Auth Server.\n" );
  63.  
  64. // network receive bufer
  65. unsigned char *netbuffer = (unsigned char *)malloc( 20*1024 ); // 20 kb ok?
  66. unsigned int rcvdLen = 0, sentLen = 0; // bytes
  67. int i = 0;
  68.  
  69. // packets objects
  70. L2LoginPacket *p_l = NULL;
  71. L2Login_Init *p_Init = NULL;
  72. L2Login_RequestGGAuth *p_rggauth = NULL;
  73. L2Login_GGAuthResponse *p_ggar = NULL;
  74. L2Login_RequestAuthLogin *p_ral = NULL;
  75. L2Login_LoginOK *p_lok = NULL;
  76. L2Login_LoginFail *p_lfail = NULL;
  77. L2Login_AccountKicked *p_acckick = NULL;
  78. L2Login_RequestServerList *p_rslist = NULL;
  79. L2Login_ServerList *p_slist = NULL;
  80. L2Login_RequestServerLogin *p_rgsl = NULL;
  81. L2Login_PlayOK *p_pok = NULL;
  82. L2Login_PlayFail *p_pfail = NULL;
  83.  
  84. // receive Init packet
  85. recvBytes = L2PacketReceive_buffer( s, 5000, &rcvdLen, netbuffer );
  86. if( recvBytes <= 0 ) // read timeout or read error
  87. {
  88. error_handler( "Recv Init" );
  89. goto cleanup;
  90. }
  91. printf( "Recv init: rcvd %u bytes\n", rcvdLen );
  92. if( rcvdLen != 186 ) // T1-T23 Init packet must be 186 bytes
  93. printf( "Warning: Init packet len != 186!\n" );
  94. else
  95. printf( "Received Init packet OK\n" );
  96.  
  97. p_Init = new L2Login_Init( netbuffer, rcvdLen );
  98. if( !p_Init->parse() )
  99. printf( "Init parse error!\n" );
  100. else
  101. printf( "Init parse OK\n" );
  102.  
  103. // out some info
  104. printf( "Login protocol version: %08x (%u)\n", p_Init->p_protoVer, p_Init->p_protoVer );
  105. printf( "Login sessionId: %02x %02x %02x %02x\n",
  106. p_Init->p_sessionId[0], p_Init->p_sessionId[1],
  107. p_Init->p_sessionId[2], p_Init->p_sessionId[3] );
  108. // check protocol
  109. if( p_Init->p_protoVer != 0x0000C621 )
  110. {
  111. error_handler( "Login protocol version invalid!" );
  112. goto cleanup;
  113. }
  114.  
  115. // send RequestGGAuth
  116. p_rggauth = new L2Login_RequestGGAuth();
  117. memcpy( p_rggauth->sessionId, p_Init->p_sessionId, 4 );
  118. p_rggauth->create();
  119. p_rggauth->encodeAndPrepareToSend( p_Init->p_BF_dyn_key );
  120. recvBytes = L2PacketSend( s, p_rggauth, 5000, &sentLen );
  121. if( recvBytes <= 0 )
  122. {
  123. error_handler( "Send RequestGGAuth failed!" );
  124. goto cleanup;
  125. }
  126. printf( "RequestGGAuth: Sent %u bytes\n", sentLen );
  127. delete p_rggauth;
  128.  
  129. // recv GGAuthResponse
  130. recvBytes = L2PacketReceive_buffer( s, 5000, &rcvdLen, netbuffer );
  131. printf( "Recv GGAuthResponse: rcvd %u bytes\n", rcvdLen );
  132. if( recvBytes <= 0 ) // read timeout or read error
  133. {
  134. error_handler( "Recv GGAuthResponse" );
  135. goto cleanup;
  136. }
  137.  
  138. p_ggar = new L2Login_GGAuthResponse( netbuffer, rcvdLen );
  139. p_ggar->decodeBlowfish( p_Init->p_BF_dyn_key );
  140. p_ggar->parse();
  141. printf( "GGAuth response: %02X %08X\n", p_ggar->getPacketType(), p_ggar->p_ggAuthResponse );
  142.  
  143. // create RequestAuthLogin
  144. p_ral = new L2Login_RequestAuthLogin();
  145. p_ral->create( l2login, l2pass, p_ggar->p_ggAuthResponse,
  146. p_Init->p_RSA_pubKeyMod );
  147. p_ral->encodeAndPrepareToSend( p_Init->p_BF_dyn_key );
  148. recvBytes = L2PacketSend( s, p_ral, 5000, &sentLen );
  149. delete p_ggar;
  150. delete p_ral;
  151. if( recvBytes <= 0 )
  152. {
  153. error_handler( "Send RequestAuthLogin failed!" );
  154. goto cleanup;
  155. }
  156. printf( "Sent %u bytes RequestAuthLogin\n", sentLen );
  157.  
  158. // receive answer to RequestAuthLogin
  159. recvBytes = L2PacketReceive_buffer( s, 5000, &rcvdLen, netbuffer );
  160. printf( "Received %u bytes\n", rcvdLen );
  161. if( recvBytes <= 0 )
  162. {
  163. error_handler( "Recv answer to RequestAuthLogin failed!" );
  164. goto cleanup;
  165. }
  166. p_l = new L2LoginPacket( netbuffer, rcvdLen );
  167. p_l->decodeBlowfish( p_Init->p_BF_dyn_key );
  168. switch( p_l->getPacketType() )
  169. {
  170. case 0x01:
  171. {
  172. printf( "Login failed!\n" );
  173. p_lfail = new L2Login_LoginFail( p_l->getBytesPtr(), p_l->getPacketSize() );
  174. // no parse() func here ><
  175. p_lfail->getPacketType();
  176. unsigned int reason = p_lfail->read_reason();
  177. char reason_str[64];
  178. p_lfail->getReasonStr( reason, reason_str );
  179. printf( "Reason: %s\n", reason_str );
  180. delete p_l;
  181. delete p_lfail;
  182. goto cleanup;
  183. } break;
  184. case 0x02:
  185. {
  186. printf( "Account kicked!\n" );
  187. p_acckick = new L2Login_AccountKicked( p_l->getBytesPtr(),
  188. p_l->getPacketSize() );
  189. p_acckick->parse();
  190. char reason_str[64];
  191. p_acckick->getReasonStr( reason_str );
  192. printf( "Reason: %s\n", reason_str );
  193. delete p_acckick;
  194. delete p_l;
  195. goto cleanup;
  196. }
  197. case 0x03:
  198. {
  199. printf( "Login OK!\n" );
  200. p_lok = new L2Login_LoginOK( p_l->getBytesPtr(), p_l->getPacketSize() );
  201. p_lok->getPacketType();
  202. p_lok->read_sessionKey1( ls_sessionKey1 );
  203. delete p_lok;
  204. } break;
  205. default:
  206. printf( "Unknown response to RequestAuthLogin: %02X\n", p_l->getPacketType() );
  207. break;
  208. }
  209. delete p_l;
  210. printf( "SessionKey1: " );
  211. for( i=0; i<8; i++ ) printf( "%02X ", ls_sessionKey1[i] );
  212. printf( "\n" );
  213.  
  214. // send RequestServerList
  215. p_rslist = new L2Login_RequestServerList();
  216. p_rslist->create( ls_sessionKey1 );
  217. p_rslist->encodeAndPrepareToSend( p_Init->p_BF_dyn_key );
  218. recvBytes = L2PacketSend( s, p_rslist, 5000, &sentLen );
  219. delete p_rslist;
  220. if( recvBytes <= 0 )
  221. {
  222. error_handler( "Send RequestServerList failed!" );
  223. goto cleanup;
  224. }
  225. printf( "Sent %u bytes: RequestServerList\n", sentLen );
  226.  
  227. // receive ServerList
  228. recvBytes = L2PacketReceive_buffer( s, 5000, &rcvdLen, netbuffer );
  229. printf( "Received %u bytes: ServerList\n", rcvdLen );
  230. if( recvBytes <= 0 )
  231. {
  232. error_handler( "Recv ServerList" );
  233. goto cleanup;
  234. }
  235. // parse
  236. p_slist = new L2Login_ServerList( netbuffer, rcvdLen );
  237. p_slist->decodeBlowfish( p_Init->p_BF_dyn_key );
  238. unsigned char gsCount, lastServerID;
  239. p_slist->read_header( &gsCount, &lastServerID );
  240. printf( "ServerList: %d game servers, last server: %d\n",
  241. (int)gsCount, (int)lastServerID );
  242. // array of game servers info
  243. L2GameServerInfo gsi[32];
  244. for( i=0; i<gsCount; i++ )
  245. {
  246. p_slist->read_next_GS_Info( &(gsi[i]) );
  247. printf( "\n==== Server ID %d ====\n", (int)gsi[i].gsID );
  248. printf( "Addr: %d.%d.%d.%d:%d\n", (int)gsi[i].gsIP[0], (int)gsi[i].gsIP[1],
  249. (int)gsi[i].gsIP[2], (int)gsi[i].gsIP[3], (int)gsi[i].gsPort );
  250. if( gsi[i].gsIsUp )
  251. {
  252. printf( "Online; Players %d / %d (%3.2f%% load)\n",
  253. gsi[i].gsPlayersOnline, gsi[i].gsPlayersMax,
  254. (100.0f * (float)gsi[i].gsPlayersOnline / (float)gsi[i].gsPlayersMax) );
  255. }
  256. else printf( "Offline\n" );
  257. }
  258. delete p_slist;
  259.  
  260. int choose_gsID;
  261. printf( "Enter game server ID to play: " );
  262. scanf( "%d", &choose_gsID );
  263.  
  264. // send RequestServerLogin with selected server ID
  265. p_rgsl = new L2Login_RequestServerLogin();
  266. p_rgsl->create( ls_sessionKey1, (unsigned char)choose_gsID );
  267. p_rgsl->encodeAndPrepareToSend( p_Init->p_BF_dyn_key );
  268. recvBytes = L2PacketSend( s, p_rgsl, 5000, &sentLen );
  269. delete p_rgsl;
  270. if( recvBytes <= 0 )
  271. {
  272. error_handler( "Send RequestServerLogin failed!" );
  273. goto cleanup;
  274. }
  275. printf( "Sent %u bytes: RequestServerLogin\n", sentLen );
  276.  
  277. // receive server response: PlayOK or PlayFail
  278. recvBytes = L2PacketReceive_buffer( s, 5000, &rcvdLen, netbuffer );
  279. printf( "Recv %u bytes: response to RequestServerLogin\n", rcvdLen );
  280. if( recvBytes <= 0 )
  281. {
  282. error_handler( "Recv PlayOK/PlayFail error" );
  283. goto cleanup;
  284. }
  285. // parse
  286. p_l = new L2LoginPacket( netbuffer, rcvdLen );
  287. p_l->decodeBlowfish( p_Init->p_BF_dyn_key );
  288. switch( p_l->getPacketType() )
  289. {
  290. case 0x06: // PlayFail
  291. {
  292. printf( "PlayFail!\n" );
  293. p_pfail = new L2Login_PlayFail( p_l->getBytesPtr(), p_l->getPacketSize() );
  294. p_pfail->getPacketType();
  295. unsigned char reasonCode = p_pfail->read_reason();
  296. char reasonStr[64];
  297. p_pfail->getReasonStr( reasonCode, reasonStr );
  298. delete p_pfail;
  299. delete p_l;
  300. printf( "Reason: %s\n", reasonStr );
  301. goto cleanup;
  302. } break;
  303. case 0x07: // PlayOK
  304. {
  305. printf( "Play OK!\n" );
  306. p_pok = new L2Login_PlayOK( p_l->getBytesPtr(), p_l->getPacketSize() );
  307. p_pok->getPacketType();
  308. p_pok->read_sessionKey2( ls_sessionKey2 );
  309. delete p_pok;
  310. } break;
  311. default:
  312. printf( "Unknows response to RequestServerLogin: %02X\n", p_l->getPacketType() );
  313. break;
  314. }
  315. delete p_l;
  316.  
  317. printf( "SessionKey2: " );
  318. for( i=0; i<8; i++ ) printf( "%02X ", ls_sessionKey2[i] );
  319. printf( "\n" );
  320.  
  321. // new we got all info to connect to game server:
  322. // server id, ip, port, session keys, account name
  323. // we can close login server connection and then connect to game server
  324.  
  325. for( i=0; i<gsCount; i++ )
  326. {
  327. if( gsi[i].gsID == (unsigned char)choose_gsID )
  328. {
  329. printf( "You choose to play on gs #%d ID %d\n", i, choose_gsID );
  330. printf( "Connect to address: %d.%d.%d.%d port %d\n",
  331. (int)gsi[i].gsIP[0], (int)gsi[i].gsIP[1],
  332. (int)gsi[i].gsIP[2], (int)gsi[i].gsIP[3],
  333. (int)gsi[i].gsPort );
  334. break;
  335. }
  336. }
  337.  
  338. cleanup:
  339. delete p_Init;
  340. free( netbuffer );
  341. L2PNet_shutdown( s );
  342. L2PNet_closesocket( s );
  343. }
  344.  
  345. void ProcessServerState( char *login )
  346. {
  347. pGameSocket = L2PNet_TCPsocket_create( true ); // create async TCP socket
  348. if( pGameSocket == INVALID_SOCKET )
  349. {
  350. error_handler( "socket creation" );
  351. return;
  352. }
  353. printf( "Socket created to Game Server...\n" );
  354.  
  355. // start connecting
  356. L2PNet_connect( pGameSocket, "90.227.223.129", 7777 );
  357.  
  358. // network vars
  359. int readyRead, readyWrite;
  360.  
  361. recvBytes = L2PNet_select( pGameSocket, L2PNET_SELECT_WRITE, 1000, &readyRead, &readyWrite );
  362. if( recvBytes == 0 )
  363. {
  364. error_handler( "Connect failed!" );
  365. return;
  366. }
  367. printf( "Connected to Game Server.\n" );
  368.  
  369. // network receive bufer
  370. GameNetBuffer = (unsigned char *)malloc( 20*1024 ); // 20 kb ok?
  371.  
  372. // packets
  373. L2Game_ProtocolVersion *p_game_pv = NULL;
  374. L2Game_AuthLogin *p_game_al = NULL;
  375.  
  376. // send ProtocolVersion
  377. p_game_pv = new L2Game_ProtocolVersion();
  378. p_game_pv->createDefaultKamael();
  379. recvBytes = L2PacketSend( pGameSocket, p_game_pv, 5000, &GameSentLen );
  380. delete p_game_pv;
  381. if( recvBytes <= 0 )
  382. {
  383. error_handler( "Send L2Game ProtocolVersion failed!" );
  384. goto cleanup;
  385. }
  386. printf( "Sent %u bytes: L2Game ProtocolVersion\n", GameSentLen );
  387.  
  388. //Get Game Key
  389. recvBytes = L2PacketReceive_buffer( pGameSocket, 5000, &GameRcvdLen, GameNetBuffer );
  390.  
  391. p_game_key = new L2Game_KeyPacket( GameNetBuffer, GameRcvdLen );
  392. p_game_key->parse( L2_VERSION_T1 );
  393. delete p_game_key;
  394. if( recvBytes <= 0 )
  395. {
  396. error_handler( "Request L2Game KeyPacket failed!" );
  397. goto cleanup;
  398. }
  399. printf( "Receive %u bytes: L2Game KeyPacket\n", GameRcvdLen );
  400.  
  401. p_game_al = new L2Game_AuthLogin();
  402. p_game_al->create( login, ls_sessionKey1, ls_sessionKey2 );
  403. recvBytes = L2PacketSend( pGameSocket, p_game_al, 5000, &GameSentLen );
  404. delete p_game_al;
  405. if( recvBytes <= 0 )
  406. {
  407. error_handler( "Send L2Game AuthLogin failed!" );
  408. goto cleanup;
  409. }
  410. printf( "Sent %u bytes: L2Game AuthLogin\n", GameSentLen );
  411.  
  412. cleanup:
  413. printf( "Finish" );
  414. // free( GameNetBuffer );
  415. // L2PNet_shutdown( pGameSocket );
  416. // L2PNet_closesocket( pGameSocket );
  417. };
  418.  
  419. void ProcessGamePackets()
  420. {
  421. recvBytes = L2PNet_select( pGameSocket, L2PNET_SELECT_READ, timerResolutionMsec, &readyRead, &readyWrite );
  422. DWORD curTick = GetTickCount();
  423. if( curTick - lastWorldTickTime >= (unsigned)timerResolutionMsec )
  424. {
  425. //printf("Tick: process world tick\n" );
  426. lastWorldTickTime = curTick;
  427. }
  428.  
  429. // select result
  430. if( recvBytes == -1 ) return;
  431.  
  432. if( L2PacketReceive_buffer( pGameSocket, timerResolutionMsec, &GameRcvdLen, GameNetBuffer ) > 0 )
  433. {
  434. unsigned int opCode = (unsigned int)GameNetBuffer[ 2 ];
  435.  
  436. if( opCode == 0x18 ) return; //Remove info packet.
  437.  
  438. printf( "OpCode: 0x%02x\n", opCode );
  439. printf( "Receive %u bytes\n", GameRcvdLen );
  440.  
  441. L2GamePacket *pGamePacket = new L2GamePacket( GameNetBuffer, GameRcvdLen );
  442.  
  443. switch( opCode )
  444. {
  445. case 0x09:
  446. {
  447. printf( "Character List:\n\n" );
  448.  
  449. // vars
  450. unsigned int nCharsInCharSelection = 0;
  451. unsigned int nServerMaxChars = 0;
  452.  
  453. L2Game_CharSelectionInfo *pCharSel = new L2Game_CharSelectionInfo( GameNetBuffer, GameRcvdLen );
  454.  
  455. // parse CharSelectionInfo
  456. pCharSel->read_nChars( &nCharsInCharSelection );
  457. pCharSel->read_server_maxChars( &nServerMaxChars );
  458.  
  459. L2Game_CharSelectionInfoBlock csb_chars[ 10 ];
  460. memset( csb_chars, 0, sizeof(csb_chars) );
  461.  
  462. printf( "Char sel: %d chars (max %d)\n", nCharsInCharSelection, nServerMaxChars );
  463.  
  464. for( int i = 0; i < (int)nCharsInCharSelection; i++ )
  465. {
  466. pCharSel->read_next_charSelectInfoBlock( L2_VERSION_T1, &csb_chars[i] );
  467.  
  468. printf( "#Slot: ( %i ) - Name: %S, Level: %i\n", i, csb_chars[ i ].charName,
  469. csb_chars[ i ].level );
  470.  
  471. //ToDo: Add players to GUI List.
  472. }
  473.  
  474. char CharSlot[10];
  475. printf( "SelectChar: " );
  476. scanf( "%s", CharSlot );
  477.  
  478. int SlotID = atoi( CharSlot );
  479.  
  480. printf( "You selected Character Slot %i\n", SlotID );
  481.  
  482. //ToDo: Select players from GUI List.
  483.  
  484. L2Game_CharacterSelect *pCharSlot = new L2Game_CharacterSelect();
  485. pCharSlot->create( (unsigned int)SlotID );
  486. recvBytes = L2PacketSend( pGameSocket, pCharSlot, 5000, &GameSentLen );
  487. delete pCharSlot;
  488. if( recvBytes <= 0 )
  489. {
  490. error_handler( "Send L2Ganetwome CharacterSelect failed!" );
  491. break;
  492. }
  493. printf( "Sent %u bytes: L2Game CharacterSelect\n", GameSentLen );
  494. break;
  495. }
  496. case 0x0B:
  497. {
  498. printf( "Character Selected!\n" );
  499.  
  500. // RequestManorList
  501. GameNetBuffer[0] = 5; GameNetBuffer[1] = 0;
  502. GameNetBuffer[2] = 0xD0; GameNetBuffer[3] = 0x01; GameNetBuffer[4] = 0x00;
  503. recvBytes = L2PacketSend2( GameNetBuffer, pGameSocket, 5000, &GameSentLen );
  504. if( recvBytes <= 0 )
  505. {
  506. error_handler( "Send RequestManorList failed!" );
  507. break;
  508. }
  509. printf( "Sent %u bytes: RequestManorList\n", GameSentLen );
  510.  
  511. // RequestKeyMapping
  512. GameNetBuffer[0] = 5; GameNetBuffer[1] = 0;
  513. GameNetBuffer[2] = 0xD0; GameNetBuffer[3] = 0x21; GameNetBuffer[4] = 0x00;
  514. recvBytes = L2PacketSend2( GameNetBuffer, pGameSocket, 5000, &GameSentLen );
  515. if( recvBytes <= 0 )
  516. {
  517. error_handler( "Send RequestKeyMapping failed!" );
  518. break;
  519. }
  520. printf( "Sent %u bytes: RequestKeyMapping\n", GameSentLen );
  521.  
  522. char EnterGame[10];
  523. printf( "EnterGame: yes/no : " );
  524. scanf( "%s", EnterGame );
  525.  
  526. if( !strcmp( EnterGame, "yes" ) )
  527. {
  528. printf( "Enter Game!\n" );
  529.  
  530. // Enter world packet ( Make the char enter the world )
  531. L2Game_EnterWorld *ew = new L2Game_EnterWorld();
  532. ew->create( L2_VERSION_T1 );
  533. recvBytes = L2PacketSend( pGameSocket, ew, 5000, &GameSentLen );
  534. delete ew;
  535. if( recvBytes <= 0 )
  536. {
  537. error_handler( "Send L2Ganetwome L2Game EnterWorld failed!" );
  538. break;
  539. }
  540. printf( "Sent %u bytes: L2Game L2Game EnterWorld\n", GameSentLen );
  541.  
  542. }
  543. break;
  544.  
  545. }
  546. case 0x62: // System Messages
  547. {
  548. L2Game_SystemMessage *pSysMsg = new L2Game_SystemMessage();
  549. pSysMsg->parse_SystemMessage( pGamePacket );
  550. delete pSysMsg;
  551. break;
  552. }
  553. case 0x31: // Char Info ( This is information from other players and NPC's / Mobs )
  554. {
  555. L2Player *pUser = new L2Player();
  556. pUser->parse_CharInfo( pGamePacket, L2_VERSION_T1 );
  557.  
  558. //objectID is unique in game world, You can use pUser->objectID to store players in some sort of map.
  559. printf( "::GamePacket:: -> CharInfo->: %S -> X: %i, Y: %i, Z: %i\n", pUser->charName, pUser->x, pUser->y, pUser->z );
  560. //printf( "::GamePacket:: -> CharInfo->ObjID( %i ): %S -> X: %i, Y: %i, Z: %i\n", pUser->objectID, pUser->charName, pUser->x, pUser->y, pUser->z );
  561.  
  562. // Add object to world list.
  563. mGameWorldObjects[ pUser->objectID ] = pUser;
  564.  
  565. L2GamePacket *gp=new L2GamePacket();
  566. gp->writeChar(0x0f);
  567.  
  568. /*gp->writeDouble(-73571.0f);
  569. gp->writeDouble(255868.0f);
  570. gp->writeDouble(-3120.0f);
  571. gp->writeDouble(pUser->x);
  572. gp->writeDouble(pUser->y);
  573. gp->writeDouble(pUser->z);*/
  574.  
  575. gp->writeInt(-73571);
  576. gp->writeInt(255868);
  577. gp->writeInt(-3120);
  578. gp->writeInt(pUser->x);
  579. gp->writeInt(pUser->y);
  580. gp->writeInt(pUser->z);
  581.  
  582.  
  583. break;
  584. }
  585. case 0x32: // User Info ( This is your information )
  586. {
  587. L2Player *pUser = new L2Player();
  588. pUser->parse_UserInfo( pGamePacket, L2_VERSION_T1 );
  589.  
  590. //objectID is unique in game world, You can use pUser->objectID to store players in some sort of map.
  591. printf( "::GamePacket:: -> UserInfo->: %S -> X: %i, Y: %i, Z: %i\n", pUser->charName, pUser->x, pUser->y, pUser->z );
  592. //printf( "::GamePacket:: -> CharInfo->ObjID( %i ): %S -> X: %i, Y: %i, Z: %i\n", pUser->objectID, pUser->charName, pUser->x, pUser->y, pUser->z );
  593.  
  594. // Add object to world list.
  595. mGameWorldObjects[ pUser->objectID ] = pUser;
  596. break;
  597. }
  598. case 0x08: // Remove object from world.
  599. {
  600. pGamePacket->getPacketType();
  601. unsigned int pObjID = pGamePacket->readUInt();
  602.  
  603. mGameWorldObjects.erase( mGameWorldObjects.find( pObjID ) );
  604.  
  605. printf( "::GamePacket:: -> Remove Object ( %i )\n", pObjID );
  606. break;
  607. }
  608. case 0xD9:
  609. {
  610. printf( "::GamePacket:: -> Ping Packet\n" );
  611. break;
  612. }
  613. }
  614. delete pGamePacket;
  615. pGamePacket = NULL;
  616. }
  617. }
  618.  
  619. int main()
  620. {
  621. L2PNet_InitDefault(); // library init?
  622.  
  623. char l2login[32];
  624. char l2pass[32];
  625. printf( "Login: " );
  626. scanf( "%s", l2login );
  627. printf( "Pass: " );
  628. scanf( "%s", l2pass );
  629.  
  630. ProcessLoginState( l2login, l2pass );
  631. printf( "\n\nGame Server Section!\n" );
  632. ProcessServerState( l2login );
  633.  
  634. lastWorldTickTime = GetTickCount();
  635.  
  636. // Process Game Packets
  637. while( TRUE ) ProcessGamePackets();
  638.  
  639. getch();
  640.  
  641. mGameWorldObjects.clear();
  642.  
  643. L2PNet_shutdown( pGameSocket );
  644. L2PNet_closesocket( pGameSocket );
  645.  
  646. return 0;
  647. }
  648.  
  649. void error_handler( const char *msg, bool is_fatal )
  650. {
  651. if( msg ) perror( msg ); else perror( "ERROR: " );
  652. if( is_fatal ) exit( 1 );
  653. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement