Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #################################################################################################
- # OpenKore - Network subsystem #
- # This module contains functions for sending messages to the server. #
- # #
- # This software is open source, licensed under the GNU General Public #
- # License, version 2. #
- # Basically, this means that you're allowed to modify and distribute #
- # this software. However, if you distribute modified versions, you MUST #
- # also distribute the source code. #
- # See http://www.gnu.org/licenses/gpl.html for the full license. #
- #################################################################################################
- # bRO (Brazil)
- package Network::Send::bRO;
- use strict;
- use Globals;
- use Log qw(message warning error debug);
- use Utils qw(existsInList getHex getTickCount getCoordString);
- use Math::BigInt;
- use base 'Network::Send::ServerType0';
- use I18N qw(stringToBytes);
- sub new {
- my ($class) = @_;
- my $self = $class->SUPER::new(@_);
- my %packets = (
- '08A9' => ['actor_action', 'a4 C', [qw(targetID type)]],
- '0881' => ['character_move','a3', [qw(coords)]],
- '093B' => ['sync', 'V', [qw(time)]],
- '0802' => ['actor_look_at', 'v C', [qw(head body)]],
- '0953' => ['item_take', 'a4', [qw(ID)]],
- '022D' => ['item_drop', 'v2', [qw(index amount)]],
- '0864' => ['storage_item_add', 'v V', [qw(index amount)]],
- '091B' => ['storage_item_remove', 'v V', [qw(index amount)]],
- '0959' => ['skill_use_location', 'v4', [qw(lv skillID x y)]],
- '095D' => ['actor_info_request', 'a4', [qw(ID)]],
- '0862' => ['map_login', 'a4 a4 a4 V C', [qw(accountID charID sessionID tick sex)]],
- '0949' => ['party_join_request_by_name', 'Z24', [qw(partyName)]],
- '0968' => ['homunculus_command', 'v C', [qw(commandType, commandID)]],
- );
- $self->{packet_list}{$_} = $packets{$_} for keys %packets;
- my %handlers = qw(
- actor_action 08A9
- character_move 0881
- sync 093B
- actor_look_at 0802
- item_take 0953
- item_drop 022D
- storage_item_add 0864
- storage_item_remove 091B
- skill_use_location 0959
- actor_info_request 095D
- map_login 0862
- party_join_request_by_name 0949
- homunculus_command 0968
- master_login 02B0
- party_setting 07D7
- buy_bulk_vender 0801
- );
- $self->{packet_lut}{$_} = $handlers{$_} for keys %handlers;
- return $self;
- }
- # Local Servertype Globals
- my $map_login = 0;
- my $enc_val3 = 0;
- sub encryptMessageID
- {
- my ($self, $r_message, $MID) = @_;
- # Checking In-Game State
- if ($self->{net}->getState() != Network::IN_GAME && !$map_login) { $enc_val1 = 0; $enc_val2 = 0; return; }
- # Turn Off Map Login Flag
- if ($map_login) { $map_login = 0; }
- # Checking if Encryption is Activated
- if ($enc_val1 != 0 && $enc_val2 != 0)
- {
- # Saving Last Informations for Debug Log
- my $oldMID = $MID;
- my $oldKey = ($enc_val1 >> 16) & 0x7FFF;
- # Calculating the Encryption Key
- $enc_val1 = $enc_val1->bmul($enc_val2)->badd($enc_val3) & 0xFFFFFFFF;
- # Xoring the Message ID
- $MID = ($MID ^ (($enc_val1 >> 16) & 0x7FFF));
- $$r_message = pack("v", $MID) . substr($$r_message, 2);
- # Debug Log
- if ($config{debugPacket_sent} == 1)
- {
- debug(sprintf("Encrypted MID : [%04X]->[%04X] / KEY : [0x%04X]->[0x%04X]\n", $oldMID, $MID, $oldKey, ($enc_val1 >> 8 >> 8) & 0x7FFF), "sendPacket", 0);
- }
- }
- }
- sub sendStoragePassword {
- my $self = shift;
- # 16 byte packed hex data
- my $pass = shift;
- # 2 = set password ?
- # 3 = give password ?
- my $type = shift;
- my $msg;
- if ($type == 3) {
- $msg = pack("v v", 0x088A, $type).$pass.pack("H*", "EC62E539BB6BBC811A60C06FACCB7EC8");
- } elsif ($type == 2) {
- $msg = pack("v v", 0x088A, $type).pack("H*", "EC62E539BB6BBC811A60C06FACCB7EC8").$pass;
- } else {
- ArgumentException->throw("The 'type' argument has invalid value ($type).");
- }
- $self->sendToServer($msg);
- }
- sub sendMapLogin
- {
- my ($self, $accountID, $charID, $sessionID, $sex) = @_;
- my $msg;
- $sex = 0 if ($sex > 1 || $sex < 0); # Sex can only be 0 (female) or 1 (male)
- if ( $map_login == 0 ) { PrepareKeys(); $map_login = 1; }
- # Reconstructing Packet
- $msg = $self->reconstruct({
- switch => 'map_login',
- accountID => $accountID,
- charID => $charID,
- sessionID => $sessionID,
- tick => getTickCount,
- sex => $sex,
- });
- $self->sendToServer($msg);
- debug "Sent sendMapLogin\n", "sendPacket", 2;
- }
- sub sendHomunculusCommand
- {
- my ($self, $command, $type) = @_; # $type is ignored, $command can be 0:get stats, 1:feed or 2:fire
- $self->sendToServer($self->reconstruct({
- switch => 'homunculus_command',
- commandType => $type,
- commandID => $command,
- }));
- debug "Sent Homunculus Command $command", "sendPacket", 2;
- }
- sub sendPartyJoinRequestByName
- {
- my ($self, $name) = @_;
- $self->sendToServer($self->reconstruct({
- switch => 'party_join_request_by_name',
- partyName => stringToBytes ($name),
- }));
- debug "Sent Request Join Party (by name): $name\n", "sendPacket", 2;
- }
- sub PrepareKeys()
- {
- # K
- $enc_val1 = Math::BigInt->new('0x68EC42E1');
- # M
- $enc_val2 = Math::BigInt->new('0x1BD66D37');
- # A
- $enc_val3 = Math::BigInt->new('0x1B555D2B');
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement