Advertisement
Guest User

Untitled

a guest
Oct 18th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. #################################################################################################
  2. # OpenKore - Network subsystem #
  3. # This module contains functions for sending messages to the server. #
  4. # #
  5. # This software is open source, licensed under the GNU General Public #
  6. # License, version 2. #
  7. # Basically, this means that you're allowed to modify and distribute #
  8. # this software. However, if you distribute modified versions, you MUST #
  9. # also distribute the source code. #
  10. # See http://www.gnu.org/licenses/gpl.html for the full license. #
  11. #################################################################################################
  12. # bRO (Brazil)
  13. package Network::Send::bRO;
  14. use strict;
  15. use Globals;
  16. use Log qw(message warning error debug);
  17. use Utils qw(existsInList getHex getTickCount getCoordString);
  18. use Math::BigInt;
  19. use base 'Network::Send::ServerType0';
  20. use I18N qw(stringToBytes);
  21.  
  22. sub new {
  23. my ($class) = @_;
  24. my $self = $class->SUPER::new(@_);
  25.  
  26. my %packets = (
  27. '08A9' => ['actor_action', 'a4 C', [qw(targetID type)]],
  28. '0881' => ['character_move','a3', [qw(coords)]],
  29. '093B' => ['sync', 'V', [qw(time)]],
  30. '0802' => ['actor_look_at', 'v C', [qw(head body)]],
  31. '0953' => ['item_take', 'a4', [qw(ID)]],
  32. '022D' => ['item_drop', 'v2', [qw(index amount)]],
  33. '0864' => ['storage_item_add', 'v V', [qw(index amount)]],
  34. '091B' => ['storage_item_remove', 'v V', [qw(index amount)]],
  35. '0959' => ['skill_use_location', 'v4', [qw(lv skillID x y)]],
  36. '095D' => ['actor_info_request', 'a4', [qw(ID)]],
  37. '0862' => ['map_login', 'a4 a4 a4 V C', [qw(accountID charID sessionID tick sex)]],
  38. '0949' => ['party_join_request_by_name', 'Z24', [qw(partyName)]],
  39. '0968' => ['homunculus_command', 'v C', [qw(commandType, commandID)]],
  40. );
  41.  
  42. $self->{packet_list}{$_} = $packets{$_} for keys %packets;
  43.  
  44. my %handlers = qw(
  45. actor_action 08A9
  46. character_move 0881
  47. sync 093B
  48. actor_look_at 0802
  49. item_take 0953
  50. item_drop 022D
  51. storage_item_add 0864
  52. storage_item_remove 091B
  53. skill_use_location 0959
  54. actor_info_request 095D
  55. map_login 0862
  56. party_join_request_by_name 0949
  57. homunculus_command 0968
  58. master_login 02B0
  59. party_setting 07D7
  60. buy_bulk_vender 0801
  61. );
  62.  
  63. $self->{packet_lut}{$_} = $handlers{$_} for keys %handlers;
  64.  
  65. return $self;
  66. }
  67.  
  68. # Local Servertype Globals
  69. my $map_login = 0;
  70. my $enc_val3 = 0;
  71.  
  72. sub encryptMessageID
  73. {
  74. my ($self, $r_message, $MID) = @_;
  75.  
  76. # Checking In-Game State
  77. if ($self->{net}->getState() != Network::IN_GAME && !$map_login) { $enc_val1 = 0; $enc_val2 = 0; return; }
  78.  
  79. # Turn Off Map Login Flag
  80. if ($map_login) { $map_login = 0; }
  81.  
  82. # Checking if Encryption is Activated
  83. if ($enc_val1 != 0 && $enc_val2 != 0)
  84. {
  85. # Saving Last Informations for Debug Log
  86. my $oldMID = $MID;
  87. my $oldKey = ($enc_val1 >> 16) & 0x7FFF;
  88.  
  89. # Calculating the Encryption Key
  90. $enc_val1 = $enc_val1->bmul($enc_val2)->badd($enc_val3) & 0xFFFFFFFF;
  91.  
  92. # Xoring the Message ID
  93. $MID = ($MID ^ (($enc_val1 >> 16) & 0x7FFF));
  94. $$r_message = pack("v", $MID) . substr($$r_message, 2);
  95.  
  96. # Debug Log
  97. if ($config{debugPacket_sent} == 1)
  98. {
  99. debug(sprintf("Encrypted MID : [%04X]->[%04X] / KEY : [0x%04X]->[0x%04X]\n", $oldMID, $MID, $oldKey, ($enc_val1 >> 8 >> 8) & 0x7FFF), "sendPacket", 0);
  100. }
  101. }
  102. }
  103.  
  104. sub sendStoragePassword {
  105. my $self = shift;
  106. # 16 byte packed hex data
  107. my $pass = shift;
  108. # 2 = set password ?
  109. # 3 = give password ?
  110. my $type = shift;
  111. my $msg;
  112. if ($type == 3) {
  113. $msg = pack("v v", 0x088A, $type).$pass.pack("H*", "EC62E539BB6BBC811A60C06FACCB7EC8");
  114. } elsif ($type == 2) {
  115. $msg = pack("v v", 0x088A, $type).pack("H*", "EC62E539BB6BBC811A60C06FACCB7EC8").$pass;
  116. } else {
  117. ArgumentException->throw("The 'type' argument has invalid value ($type).");
  118. }
  119. $self->sendToServer($msg);
  120. }
  121.  
  122. sub sendMapLogin
  123. {
  124. my ($self, $accountID, $charID, $sessionID, $sex) = @_;
  125. my $msg;
  126.  
  127. $sex = 0 if ($sex > 1 || $sex < 0); # Sex can only be 0 (female) or 1 (male)
  128.  
  129. if ( $map_login == 0 ) { PrepareKeys(); $map_login = 1; }
  130.  
  131. # Reconstructing Packet
  132. $msg = $self->reconstruct({
  133. switch => 'map_login',
  134. accountID => $accountID,
  135. charID => $charID,
  136. sessionID => $sessionID,
  137. tick => getTickCount,
  138. sex => $sex,
  139. });
  140.  
  141. $self->sendToServer($msg);
  142. debug "Sent sendMapLogin\n", "sendPacket", 2;
  143. }
  144.  
  145. sub sendHomunculusCommand
  146. {
  147. my ($self, $command, $type) = @_; # $type is ignored, $command can be 0:get stats, 1:feed or 2:fire
  148.  
  149. $self->sendToServer($self->reconstruct({
  150. switch => 'homunculus_command',
  151. commandType => $type,
  152. commandID => $command,
  153. }));
  154.  
  155. debug "Sent Homunculus Command $command", "sendPacket", 2;
  156. }
  157.  
  158. sub sendPartyJoinRequestByName
  159. {
  160. my ($self, $name) = @_;
  161.  
  162. $self->sendToServer($self->reconstruct({
  163. switch => 'party_join_request_by_name',
  164. partyName => stringToBytes ($name),
  165. }));
  166.  
  167. debug "Sent Request Join Party (by name): $name\n", "sendPacket", 2;
  168. }
  169.  
  170. sub PrepareKeys()
  171. {
  172. # K
  173. $enc_val1 = Math::BigInt->new('0x68EC42E1');
  174. # M
  175. $enc_val2 = Math::BigInt->new('0x1BD66D37');
  176. # A
  177. $enc_val3 = Math::BigInt->new('0x1B555D2B');
  178. }
  179.  
  180. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement