Skip to content

Commit 6daca03

Browse files
committed
Fixed double login bug, added gm permissions, added checks to gm commands, update your postgresql db
1 parent 5fd06f8 commit 6daca03

11 files changed

Lines changed: 59 additions & 15 deletions

nge.backup

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ CREATE TABLE accounts (
6262
id integer NOT NULL,
6363
"user" character varying(16) NOT NULL,
6464
pass character varying(34) NOT NULL,
65-
email character varying(32) NOT NULL
65+
email character varying(32) NOT NULL,
66+
gmflag boolean
6667
);
6768

6869

ngengine_public.jar

141 KB
Binary file not shown.

src/protocol/swg/LoginClusterStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import org.apache.mina.core.buffer.IoBuffer;
2828

29+
import engine.clients.Client;
30+
2931
public class LoginClusterStatus extends SWGMessage {
3032

3133
private byte[] servers;
@@ -46,7 +48,7 @@ public IoBuffer serialize() {
4648
result.flip();
4749
return result;
4850
}
49-
public void addServer(int galaxyID, String serverIP, int serverPort, int pingPort, int maxCharacters, int status, int recommended, int population) {
51+
public void addServer(int galaxyID, String serverIP, int serverPort, int pingPort, int maxCharacters, int status, int recommended, int population, Client client) {
5052
IoBuffer result = IoBuffer.allocate(39 + serverIP.length()).order(ByteOrder.LITTLE_ENDIAN);
5153

5254
int populationStatus = 0;
@@ -64,6 +66,8 @@ else if (population == 3000) {
6466
populationStatus = 6;
6567
status = 3;
6668
}
69+
if(status == 3 && client.isGM())
70+
status = 2;
6771
result.putInt(populationStatus); // 0 = very light, 1 = light, 2 = medium , 3 = heavy, 4 = very heavy, 5 = extremely heavy, 6 = full
6872
result.putInt(maxCharacters);
6973
//result.putInt(0xFFFF8F80); // Distance?

src/resources/objects/player/PlayerMessageBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ public IoBuffer buildBaseline8() {
156156

157157
if(player.getXpList().isEmpty()) {
158158
buffer.putInt(0);
159-
buffer.putInt(0);
159+
buffer.putInt(player.getXpListUpdateCounter());
160160
} else {
161161
buffer.putInt(player.getXpList().size());
162-
buffer.putInt(0);
162+
buffer.putInt(player.getXpListUpdateCounter());
163163

164164
// no need for locking here, concurrent hash map iterator wont throw concurrency exceptions and multiple thread access at zone in is unlikely to occur for the PlayerObject
165165
for(Entry<String, Integer> entry : player.getXpList().entrySet()) {

src/services/CharacterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public void handlePacket(IoSession session, IoBuffer data) throws Exception {
328328
CreateCharacterSuccess success = new CreateCharacterSuccess(object.getObjectID());
329329
session.write(new HeartBeatMessage().serialize());
330330
session.write(core.loginService.getLoginCluster().serialize());
331-
session.write(core.loginService.getLoginClusterStatus().serialize());
331+
session.write(core.loginService.getLoginClusterStatus(client).serialize());
332332

333333
session.write(success.serialize());
334334
session.write((new ClientMfdStatusUpdateMessage((float) 2, "/GroundHUD.MFDStatus.vsp.role.targetLevel")).serialize());

src/services/ConnectionService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public void handlePacket(IoSession session, IoBuffer data) throws Exception {
9494
if (resultSet.next()) {
9595
client.setAccountId(resultSet.getLong("accountId"));
9696
client.setSessionKey(clientIdMsg.getSessionKey());
97+
client.setGM(core.loginService.checkForGmPermission((int) resultSet.getLong("accountId")));
9798
AccountFeatureBits accountFeatureBits = new AccountFeatureBits();
9899
ClientPermissionsMessage clientPermissionsMessage = new ClientPermissionsMessage();
99100
session.write(new HeartBeatMessage().serialize());

src/services/LoginService.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void handlePacket(IoSession session, IoBuffer data) throws Exception {
133133
client.setAccountId(id);
134134
//client.setAccountEmail(email);
135135
client.setSession(session);
136+
client.setGM(checkForGmPermission(id));
136137

137138
core.addClient((Integer)session.getAttribute("connectionId"), client);
138139

@@ -143,7 +144,7 @@ public void handlePacket(IoSession session, IoBuffer data) throws Exception {
143144
persistSession(client);
144145

145146
LoginEnumCluster servers = getLoginCluster();
146-
LoginClusterStatus serverStatus = getLoginClusterStatus();
147+
LoginClusterStatus serverStatus = getLoginClusterStatus(client);
147148
EnumerateCharacterId characters = getEnumerateCharacterId(id);
148149

149150
LoginClientToken clientToken = new LoginClientToken(client.getSessionKey(), id, user);
@@ -205,6 +206,18 @@ public void shutdown() {
205206

206207
}
207208

209+
public boolean checkForGmPermission(int id) {
210+
PreparedStatement preparedStatement;
211+
try {
212+
preparedStatement = databaseConnection1.preparedStatement("SELECT * FROM characters WHERE \"accountId\"=" + id + "");
213+
ResultSet resultSet = preparedStatement.executeQuery();
214+
return resultSet.getBoolean("gmflag");
215+
} catch (SQLException e) {
216+
e.printStackTrace();
217+
}
218+
return false;
219+
}
220+
208221
/**
209222
* Saves session data to DB so Zone Server can link sessions to accounts.
210223
* @param client Client that needs a session save.
@@ -287,7 +300,7 @@ public LoginEnumCluster getLoginCluster() {
287300
* Generates LoginClusterStatus packet.
288301
* @return LoginClusterStatus packet.
289302
*/
290-
public LoginClusterStatus getLoginClusterStatus() {
303+
public LoginClusterStatus getLoginClusterStatus(Client client) {
291304
LoginClusterStatus clusterStatus = new LoginClusterStatus();
292305
ResultSet resultSet;
293306
try {
@@ -302,7 +315,8 @@ public LoginClusterStatus getLoginClusterStatus() {
302315
100,
303316
resultSet.getInt("statusId"),
304317
1,
305-
core.getActiveZoneClients());
318+
core.getActiveZoneClients(),
319+
client);
306320
} catch (SQLException e) {
307321
e.printStackTrace();
308322
}

src/services/SimulationService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ public SimulationService(NGECore core) {
126126
core.commandService.registerCommand("sitserver");
127127
core.commandService.registerCommand("kneel");
128128
core.commandService.registerCommand("serverdestroyobject");
129-
core.commandService.registerCommand("giveitem");
130-
core.commandService.registerCommand("object");
129+
core.commandService.registerGmCommand("giveitem");
130+
core.commandService.registerGmCommand("object");
131131
core.commandService.registerCommand("getattributesbatch");
132132
core.commandService.registerCommand("pvp");
133133
core.commandService.registerCommand("setcurrentskilltitle");
134134
core.commandService.registerCommand("tip");
135135
core.commandService.registerCommand("faction");
136-
core.commandService.registerCommand("setspeed");
136+
core.commandService.registerGmCommand("setspeed");
137137
core.commandService.registerCommand("waypoint");
138138
core.commandService.registerCommand("setwaypointactivestatus");
139139
core.commandService.registerCommand("setwaypointname");
@@ -145,7 +145,7 @@ public SimulationService(NGECore core) {
145145
core.commandService.registerCommand("boardshuttle");
146146
core.commandService.registerCommand("getplayerid");
147147
core.commandService.registerCommand("inspire");
148-
core.commandService.registerCommand("setgodmode");
148+
core.commandService.registerGmCommand("setgodmode");
149149
core.commandService.registerCommand("requestwaypointatposition");
150150
core.commandService.registerCommand("meditate");
151151

@@ -547,6 +547,7 @@ public void handleDisconnect(IoSession session) {
547547
return;
548548

549549
CreatureObject object = (CreatureObject) client.getParent();
550+
object.setClient(null);
550551
PlayerObject ghost = (PlayerObject) object.getSlottedObject("ghost");
551552

552553
if(object.getGroupId() != 0)
@@ -590,11 +591,11 @@ public void handleDisconnect(IoSession session) {
590591
// object.getContainer().remove(object);
591592
//}
592593

593-
core.objectService.destroyObject(object);
594594

595595
object.createTransaction(core.getCreatureODB().getEnvironment());
596596
core.getCreatureODB().put(object, Long.class, CreatureObject.class, object.getTransaction());
597597
object.getTransaction().commitSync();
598+
core.objectService.destroyObject(object);
598599

599600
core.getActiveConnectionsMap().remove((Integer) session.getAttribute("connectionId"));
600601

src/services/command/BaseSWGCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class BaseSWGCommand implements Cloneable {
3030
private String clientEffectTarget;
3131
private int maxRangeToTarget;
3232
private int commandCRC;
33+
private boolean isGmCommand = false;
3334

3435
public BaseSWGCommand(String commandName) {
3536
setCommandName(commandName);
@@ -80,4 +81,12 @@ public Object clone() throws CloneNotSupportedException {
8081
return super.clone();
8182
}
8283

84+
public boolean isGmCommand() {
85+
return isGmCommand;
86+
}
87+
88+
public void setGmCommand(boolean isGmCommand) {
89+
this.isGmCommand = isGmCommand;
90+
}
91+
8392
}

src/services/command/CommandService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public void handlePacket(IoSession session, IoBuffer data) throws Exception {
9595
System.out.println("NULL Object");
9696
return;
9797
}
98+
99+
if(command.isGmCommand() && !client.isGM())
100+
return;
98101

99102
CreatureObject actor = (CreatureObject) client.getParent();
100103

@@ -131,6 +134,15 @@ public CombatCommand registerCombatCommand(String name) {
131134

132135
}
133136

137+
public BaseSWGCommand registerGmCommand(String name) {
138+
139+
BaseSWGCommand command = new BaseSWGCommand(name.toLowerCase());
140+
command.setGmCommand(true);
141+
commandLookup.add(command);
142+
return command;
143+
144+
}
145+
134146
public void registerAlias(String name, String target) {
135147
Vector<BaseSWGCommand> commands = new Vector<BaseSWGCommand>(commandLookup); // copy for thread safety
136148
BaseSWGCommand targetCommand = null;

0 commit comments

Comments
 (0)