forked from OpenKore/openkore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpRO.pm
More file actions
173 lines (145 loc) · 6.22 KB
/
pRO.pm
File metadata and controls
173 lines (145 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#########################################################################
# OpenKore - Network subsystem
# Copyright (c) 2006 OpenKore Team
#
# 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.
#########################################################################
# pRO (Philippines)
# Servertype overview: http://wiki.openkore.com/index.php/ServerType
package Network::Receive::pRO;
use strict;
use base qw(Network::Receive::ServerType0);
use Globals;
use Log qw(message warning error debug);
use Translation;
use Misc;
use Utils qw(timeOut getFormattedDate);
use I18N qw(bytesToString stringToBytes);
use Time::HiRes qw(time);
sub new {
my ($class) = @_;
my $self = $class->SUPER::new(@_);
my %packets = (
'006D' => ['character_creation_successful', 'a4 V9 v V2 v14 Z24 C6 v2', [qw(charID exp zeny exp_job lv_job opt1 opt2 option stance manner points_free hp hp_max sp sp_max walk_speed type hair_style weapon lv points_skill lowhead shield tophead midhead hair_color clothes_color name str agi vit int dex luk slot renameflag)]],
'0097' => ['private_message', 'v Z24 V Z*', [qw(len privMsgUser flag privMsg)]], # -1
'082D' => ['received_characters_info', 'x2 C5 x20', [qw(normal_slot premium_slot billing_slot producible_slot valid_slot)]],
'099D' => ['received_characters', 'v a*', [qw(len charInfo)]],
);
foreach my $switch (keys %packets) {
$self->{packet_list}{$switch} = $packets{$switch};
}
my %handlers = qw(
received_characters 099D
actor_exists 0856
actor_connected 0857
actor_moved 0858
account_id 0283
);
$self->{packet_lut}{$_} = $handlers{$_} for keys %handlers;
return $self;
}
sub received_characters_info {
my ($self, $args) = @_;
Scalar::Util::weaken(my $weak = $self);
my $timeout = {timeout => 6, time => time};
$self->{charSelectTimeoutHook} = Plugins::addHook('Network::serverConnect/special' => sub {
if ($weak && timeOut($timeout)) {
$weak->received_characters({charInfo => '', RAW_MSG_SIZE => 4});
}
});
$self->{charSelectHook} = Plugins::addHook(charSelectScreen => sub {
if ($weak) {
Plugins::delHook(delete $weak->{charSelectTimeoutHook}) if $weak->{charSelectTimeoutHook};
}
});
$timeout{charlogin}{time} = time;
$self->received_characters($args);
}
sub received_characters {
return if ($net->getState() == Network::IN_GAME);
my ($self, $args) = @_;
$net->setState(Network::CONNECTED_TO_LOGIN_SERVER);
$charSvrSet{normal_slot} = $args->{normal_slot} if (exists $args->{normal_slot});
$charSvrSet{premium_slot} = $args->{premium_slot} if (exists $args->{premium_slot});
$charSvrSet{billing_slot} = $args->{billing_slot} if (exists $args->{billing_slot});
$charSvrSet{producible_slot} = $args->{producible_slot} if (exists $args->{producible_slot});
$charSvrSet{valid_slot} = $args->{valid_slot} if (exists $args->{valid_slot});
undef $conState_tries;
Plugins::callHook('parseMsg/recvChars', $args->{options});
if ($args->{options} && exists $args->{options}{charServer}) {
$charServer = $args->{options}{charServer};
} else {
$charServer = $net->serverPeerHost . ":" . $net->serverPeerPort;
}
# PACKET_HC_ACCEPT_ENTER2 contains no character info
return unless exists $args->{charInfo};
my $blockSize = $self->received_characters_blockSize();
for (my $i = $args->{RAW_MSG_SIZE} % $blockSize; $i < $args->{RAW_MSG_SIZE}; $i += $blockSize) {
#exp display bugfix - chobit andy 20030129
my $unpack_string = $self->received_characters_unpackString;
# TODO: What would be the $unknown ?
my ($cID,$exp,$zeny,$jobExp,$jobLevel, $opt1, $opt2, $option, $stance, $manner, $statpt,
$hp,$maxHp,$sp,$maxSp, $walkspeed, $jobId,$hairstyle, $weapon, $level, $skillpt,$headLow, $shield,$headTop,$headMid,$hairColor,
$clothesColor,$name,$str,$agi,$vit,$int,$dex,$luk,$slot, $rename, $unknown, $mapname, $deleteDate) =
unpack($unpack_string, substr($args->{RAW_MSG}, $i));
$chars[$slot] = new Actor::You;
# Re-use existing $char object instead of re-creating it.
# Required because existing AI sequences (eg, route) keep a reference to $char.
$chars[$slot] = $char if $char && $char->{ID} eq $accountID && $char->{charID} eq $cID;
$chars[$slot]{ID} = $accountID;
$chars[$slot]{charID} = $cID;
$chars[$slot]{exp} = $exp;
$chars[$slot]{zeny} = $zeny;
$chars[$slot]{exp_job} = $jobExp;
$chars[$slot]{lv_job} = $jobLevel;
$chars[$slot]{hp} = $hp;
$chars[$slot]{hp_max} = $maxHp;
$chars[$slot]{sp} = $sp;
$chars[$slot]{sp_max} = $maxSp;
$chars[$slot]{jobID} = $jobId;
$chars[$slot]{hair_style} = $hairstyle;
$chars[$slot]{lv} = $level;
$chars[$slot]{headgear}{low} = $headLow;
$chars[$slot]{headgear}{top} = $headTop;
$chars[$slot]{headgear}{mid} = $headMid;
$chars[$slot]{hair_color} = $hairColor;
$chars[$slot]{clothes_color} = $clothesColor;
$chars[$slot]{name} = $name;
$chars[$slot]{str} = $str;
$chars[$slot]{agi} = $agi;
$chars[$slot]{vit} = $vit;
$chars[$slot]{int} = $int;
$chars[$slot]{dex} = $dex;
$chars[$slot]{luk} = $luk;
$chars[$slot]{sex} = $accountSex2;
$chars[$slot]{deleteDate} = getFormattedDate($deleteDate) if ($deleteDate);
$chars[$slot]{nameID} = unpack("V", $chars[$slot]{ID});
$chars[$slot]{name} = bytesToString($chars[$slot]{name});
}
my $nChars = 0;
foreach (@chars) { $nChars++ if($_); }
# FIXME better support for multiple received_characters packets
if ($args->{switch} eq '099D' && $args->{RAW_MSG_SIZE} >= ($blockSize * 3)) {
$net->setState(1.5);
return;
}
message T("Received characters from Character Server\n"), "connection";
if (!$masterServer->{pinCode}) {
if (charSelectScreen(1) == 1) {
$firstLoginMap = 1;
$startingzeny = $chars[$config{'char'}]{'zeny'} unless defined $startingzeny;
$sentWelcomeMessage = 1;
}
} else {
message T("Waiting for PIN code request\n"), "connection";
$timeout{'charlogin'}{'time'} = time;
}
}
*parse_quest_update_mission_hunt = *Network::Receive::parse_quest_update_mission_hunt_v2;
*reconstruct_quest_update_mission_hunt = *Network::Receive::reconstruct_quest_update_mission_hunt_v2;
1;