-
Notifications
You must be signed in to change notification settings - Fork 17
/
CM_CHAR_CREATE.java
190 lines (176 loc) · 6.49 KB
/
CM_CHAR_CREATE.java
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.client;
import static com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason.REASON_16_ENG_CHARS;
import static com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason.REASON_CHOOSE_ANOTHER_SVR;
import static com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason.REASON_CREATION_FAILED;
import static com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason.REASON_NAME_ALREADY_EXISTS;
import static com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason.REASON_TOO_MANY_CHARACTERS;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_OK;
import com.l2jserver.model.template.actor.ActorSex;
import com.l2jserver.model.template.character.CharacterClass;
import com.l2jserver.model.template.character.CharacterRace;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle;
import com.l2jserver.service.game.character.CharacteCreationNotAllowedException;
import com.l2jserver.service.game.character.CharacterInvalidAppearanceException;
import com.l2jserver.service.game.character.CharacterInvalidNameException;
import com.l2jserver.service.game.character.CharacterInvalidRaceException;
import com.l2jserver.service.game.character.CharacterInvalidSexException;
import com.l2jserver.service.game.character.CharacterNameAlreadyExistsException;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.character.TooManyCharactersException;
import com.l2jserver.service.network.model.Lineage2Client;
import com.l2jserver.service.network.model.packet.AbstractClientPacket;
import com.l2jserver.util.BufferUtils;
/**
* Completes the creation of an character. Creates the object, inserts into the
* database and notifies the client about the status of the operation.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CM_CHAR_CREATE extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x0b;
// services and daos
/**
* The {@link CharacterService} implementation
*/
private final CharacterService characterService;
// packet
/**
* The name of the new character
*/
private String name;
/**
* The race of the new character. Note that this is ignored and the template
* value is used.
*/
@SuppressWarnings("unused")
private CharacterRace race;
/**
* The sex of the new character. Note that this is ignored and the template
* value is used.
*/
private ActorSex sex;
/**
* The class of the new character
*/
private CharacterClass characterClass;
/**
* The new character intelligence. Note that this is ignored and the
* template value is used.
*/
@SuppressWarnings("unused")
private int intelligence;
/**
* The new character intelligence. Note that this is ignored and the
* template value is used.
*/
@SuppressWarnings("unused")
private int strength;
/**
* The new character strength. Note that this is ignored and the template
* value is used.
*/
@SuppressWarnings("unused")
private int concentration;
/**
* The new character concentration. Note that this is ignored and the
* template value is used.
*/
@SuppressWarnings("unused")
private int mentality;
/**
* The new character mentality. Note that this is ignored and the template
* value is used.
*/
@SuppressWarnings("unused")
private int dexterity;
/**
* The new character dexterity. Note that this is ignored and the template
* value is used.
*/
@SuppressWarnings("unused")
private int witness;
/**
* The new character hair style
*/
private CharacterHairStyle hairStyle;
/**
* The new character hair color
*/
private CharacterHairColor hairColor;
/**
* The new character face
*/
private CharacterFace face;
/**
* @param characterService
* the character service
*/
@Inject
public CM_CHAR_CREATE(CharacterService characterService) {
this.characterService = characterService;
}
@Override
public void read(Lineage2Client conn, ChannelBuffer buffer) {
name = BufferUtils.readString(buffer);
race = CharacterRace.fromOption(buffer.readInt());
sex = ActorSex.fromOption(buffer.readInt());
characterClass = CharacterClass.fromID(buffer.readInt());
intelligence = buffer.readInt();
strength = buffer.readInt();
concentration = buffer.readInt();
mentality = buffer.readInt();
dexterity = buffer.readInt();
witness = buffer.readInt();
hairStyle = CharacterHairStyle.fromOption(buffer.readInt());
hairColor = CharacterHairColor.fromOption(buffer.readInt());
face = CharacterFace.fromOption(buffer.readInt());
}
@Override
public void process(final Lineage2Client conn) {
try {
final L2Character character = characterService.create(name, conn
.getSession().getAccountID(), sex, characterClass,
hairStyle, hairColor, face);
if (character != null)
conn.write(SM_CHAR_CREATE_OK.INSTANCE);
else
conn.write(REASON_CREATION_FAILED.newInstance());
} catch (CharacterInvalidNameException e) {
conn.write(REASON_16_ENG_CHARS.newInstance());
} catch (CharacterInvalidAppearanceException e) {
conn.write(REASON_CREATION_FAILED.newInstance());
} catch (CharacterNameAlreadyExistsException e) {
conn.write(REASON_NAME_ALREADY_EXISTS.newInstance());
} catch (CharacteCreationNotAllowedException e) {
conn.write(REASON_CREATION_FAILED.newInstance());
} catch (CharacterInvalidRaceException | CharacterInvalidSexException e) {
conn.write(REASON_CHOOSE_ANOTHER_SVR.newInstance());
} catch (TooManyCharactersException e) {
conn.write(REASON_TOO_MANY_CHARACTERS.newInstance());
}
}
}