Skip to content

Commit

Permalink
solving concurrency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Faris-Mckay committed Jun 7, 2015
1 parent 20de2d7 commit 7e7c6ae
Show file tree
Hide file tree
Showing 27 changed files with 682 additions and 216 deletions.
11 changes: 8 additions & 3 deletions logic/org/solace/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class Game {
/**
* List containing all players in queue waiting to be registered to game
*/
public static List<Player> registryQueue = new LinkedList<Player>();
public static LinkedList<Player> registryQueue = new LinkedList<Player>();


/**
* Stores the singleton instance of the game class
Expand Down Expand Up @@ -103,15 +104,19 @@ public void deregister(Player player) {
}

/**
* Synchronizes the registry queue with the real game repository and clears
* Synchronises the registry queue with the real game repository and clears
* the registry after
*/
public void syncCycleRegistrys() {
if (registryQueue.isEmpty()) {
return;
}
for (Player player : registryQueue) {
LinkedList<Player> queue = (LinkedList) registryQueue.clone();
for (Player player : queue) {
if (player.isLogoutRequired()) {
if(!player.isGenuineDisconnection()){
player.handleDisconnection();
}
getPlayerRepository().remove(player.getIndex());
IndexManager.freeIndex(player.getIndex());
player = null;
Expand Down
55 changes: 42 additions & 13 deletions logic/org/solace/game/entity/mobile/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package org.solace.game.entity.mobile.player;

import org.solace.game.entity.mobile.update.impl.PlayerUpdateTask;
import java.util.Random;
import org.solace.Server;
import org.solace.event.events.PlayerDisconnectionEvent;
import org.solace.event.events.PlayerLoginEvent;
import org.solace.event.events.PlayerLogoutEvent;
import org.solace.event.impl.PlayerDeathService;
Expand All @@ -29,7 +31,7 @@
import org.solace.game.content.skills.SkillHandler;
import org.solace.game.entity.UpdateFlags.UpdateFlag;
import org.solace.game.entity.mobile.Mobile;
import org.solace.game.entity.mobile.npc.NPCUpdateTask;
import org.solace.game.entity.mobile.update.impl.NPCUpdateTask;
import org.solace.game.item.container.impl.Banking;
import org.solace.game.item.container.impl.Equipment;
import org.solace.game.item.container.impl.Inventory;
Expand Down Expand Up @@ -65,9 +67,7 @@ public class Player extends Mobile {
private PlayerSettings settings = new PlayerSettings();
private Banking banking = new Banking(this);

/*
* Cached details.
*/

/**
* The cached update block.
*/
Expand Down Expand Up @@ -98,9 +98,10 @@ public void appendLoginAttributes() {
private int prayerIcon = -1;
private double prayerDrainRate;
public long foodDelay;
private boolean genuineDisconnection = false, disconnectionHandled;

public Player(String username, String password, RSChannelContext channelContext) {
super(new Location(3200 + new Random().nextInt(200),3200+ new Random().nextInt(200)));
super(new Location(3200,3200));
this.authenticator = new PlayerAuthentication(username, password);
this.channelContext = channelContext;
setDefaultAppearance();
Expand All @@ -116,20 +117,12 @@ public Player(String username, String password, RSChannelContext channelContext)
public void update() {
getMobilityManager().processMovement();
if (getStatus() != WelfareStatus.DEAD) {
/*
* Combat tick
*/
Combat.handleCombatTick(this);
if (inWild()) {
getPacketDispatcher().sendWalkableInterface(197);
getPacketDispatcher().sendString(199, "@yel@Level: " + getWildernessLevel());
}

/*
* Prayer draining
*/
PrayerHandler.handlePrayerDraining(this);

getSkills().handleSkillRestoring();
}
}
Expand Down Expand Up @@ -174,12 +167,20 @@ public void handleLoginData() {
* Schedules a new logout event event for this player
*/
public void handleLogoutData() {
setGenuineDisconnection(true);
if (System.currentTimeMillis() - getCombatDelay() > 10000) {
Server.getEventManager().dispatchEvent(new PlayerLogoutEvent(this));
} else {
getPacketDispatcher().sendMessage("You must wait a few seconds before loggout out of combat.");
}
}

public void handleDisconnection(){
if(!isDisconnectionHandled()){
Server.getEventManager().dispatchEvent(new PlayerDisconnectionEvent(this));
setDisconnectionHandled(true);
}
}

/**
* @return the playerMessaging
Expand Down Expand Up @@ -496,4 +497,32 @@ public void setBuryingBones(boolean burying) {
this.buryingBones = burying;
}

/**
* @return the genuineDisconnection
*/
public boolean isGenuineDisconnection() {
return genuineDisconnection;
}

/**
* @param genuineDisconnection the genuineDisconnection to set
*/
public void setGenuineDisconnection(boolean genuineDisconnection) {
this.genuineDisconnection = genuineDisconnection;
}

/**
* @return the disconnectionHandled
*/
public boolean isDisconnectionHandled() {
return disconnectionHandled;
}

/**
* @param disconnectionHandled the disconnectionHandled to set
*/
public void setDisconnectionHandled(boolean disconnectionHandled) {
this.disconnectionHandled = disconnectionHandled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@
import java.util.Map;

import org.solace.game.entity.mobile.player.Player;
import org.solace.game.entity.mobile.player.command.impl.ChangeLookCommand;
import org.solace.game.entity.mobile.player.command.impl.CheckPositionCommand;
import org.solace.game.entity.mobile.player.command.impl.EmptyInventoryCommand;
import org.solace.game.entity.mobile.player.command.impl.MapTeleportCommand;
import org.solace.game.entity.mobile.player.command.impl.MasterStatsCommand;
import org.solace.game.entity.mobile.player.command.impl.PlayAnimationCommand;
import org.solace.game.entity.mobile.player.command.impl.PlayGraphicCommand;
import org.solace.game.entity.mobile.player.command.impl.PlayerTeleportCommand;
import org.solace.game.entity.mobile.player.command.impl.PlayersCheckCommand;
import org.solace.game.entity.mobile.player.command.impl.SetLevelCommand;
import org.solace.game.entity.mobile.player.command.impl.SetSidebarCommand;
import org.solace.game.entity.mobile.player.command.impl.SpawnItemCommand;
import org.solace.game.entity.mobile.player.command.impl.SpawnNPCCommand;
import org.solace.game.entity.mobile.player.command.impl.SpawnObjectCommand;

/**
* Handles the storing and processing of commands
*
* @author Arithium
* @author Faris <https://github.com/faris-mckay>
*
*/
public class CommandHandler {
Expand All @@ -35,6 +47,18 @@ public class CommandHandler {
public static void loadCommands() {
commandMap.put("item", new SpawnItemCommand());
commandMap.put("npc", new SpawnNPCCommand());
commandMap.put("players", new PlayersCheckCommand());
commandMap.put("master", new MasterStatsCommand());
commandMap.put("object", new SpawnObjectCommand());
commandMap.put("anim", new PlayAnimationCommand());
commandMap.put("gfx", new PlayGraphicCommand());
commandMap.put("mypos", new CheckPositionCommand());
commandMap.put("tele", new MapTeleportCommand());
commandMap.put("teleto", new PlayerTeleportCommand());
commandMap.put("setlevel", new SetLevelCommand());
commandMap.put("sidebar", new SetSidebarCommand());
commandMap.put("empty", new EmptyInventoryCommand());
commandMap.put("changelook", new ChangeLookCommand());
}

public static void processCommand(Player player, String command) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of Solace Framework.
* Solace 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.
*
* Solace 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
* Solace. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.solace.game.entity.mobile.player.command.impl;

import org.solace.game.entity.mobile.player.Player;
import org.solace.game.entity.mobile.player.PrivilegeRank;
import org.solace.game.entity.mobile.player.command.Command;

/**
*
* @author Faris <https://github.com/faris-mckay>
*/
public class ChangeLookCommand extends Command {

@Override
public void handle(Player player, String command) {
player.getPacketDispatcher().sendInterface(3559);
}

@Override
public PrivilegeRank rightsRequired() {
return PrivilegeRank.MODERATOR;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of Solace Framework.
* Solace 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.
*
* Solace 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
* Solace. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.solace.game.entity.mobile.player.command.impl;

import org.solace.game.entity.mobile.player.Player;
import org.solace.game.entity.mobile.player.PrivilegeRank;
import org.solace.game.entity.mobile.player.command.Command;

/**
*
* @author Faris <https://github.com/faris-mckay>
*/
public class CheckPositionCommand extends Command {

@Override
public void handle(Player player, String command) {
player.getAdvocate().displayChatboxText("X: " + player.getLocation().getX() + " Y: " + player.getLocation().getY());
}

@Override
public PrivilegeRank rightsRequired() {
return PrivilegeRank.MODERATOR;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of Solace Framework.
* Solace 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.
*
* Solace 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
* Solace. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.solace.game.entity.mobile.player.command.impl;

import org.solace.game.entity.mobile.player.Player;
import org.solace.game.entity.mobile.player.PrivilegeRank;
import org.solace.game.entity.mobile.player.command.Command;

/**
*
* @author Faris <https://github.com/faris-mckay>
*/
public class EmptyInventoryCommand extends Command {

@Override
public void handle(Player player, String command) {
for (int i = 0; i < 28; i++) {
player.getInventory().set(i, -1, 0);
player.getInventory().refreshItems();
}
}

@Override
public PrivilegeRank rightsRequired() {
return PrivilegeRank.STANDARD;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of Solace Framework.
* Solace 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.
*
* Solace 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
* Solace. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.solace.game.entity.mobile.player.command.impl;

import org.solace.game.entity.mobile.player.Player;
import org.solace.game.entity.mobile.player.PrivilegeRank;
import org.solace.game.entity.mobile.player.command.Command;
import org.solace.game.map.Location;

/**
*
* @author Faris <https://github.com/faris-mckay>
*/
public class MapTeleportCommand extends Command {

@Override
public void handle(Player player, String command) {
String[] args = command.split(" ");
String secondWord = args[1].toLowerCase();
if (args.length == 3) {
int x = Integer.parseInt(secondWord);
int y = Integer.parseInt(args[2]);
int z = Integer.parseInt(args[3]);
player.getMobilityManager().processTeleport(player, new Location(x, y, z));
}
}

@Override
public PrivilegeRank rightsRequired() {
return PrivilegeRank.MODERATOR;
}

}
Loading

0 comments on commit 7e7c6ae

Please sign in to comment.