This commit is contained in:
Light2
2013-07-29 22:01:04 +02:00
48 changed files with 2933 additions and 375 deletions
+2 -2
View File
@@ -8,6 +8,6 @@ PING.PORT=44462
DB.NAME=nge
DB.USER=postgres
DB.URL=localhost
DB.PASS=
DB.PASS=nge
GALAXY_ID=2
GALAXY_NAME=Local Connection
GALAXY_NAME=Local Connection
+28
View File
@@ -0,0 +1,28 @@
from resources.objects.creature import CreatureObject
import sys
def setup():
return
def run(core, actor, target, commandString):
actorFaction = actor.getFaction()
actorStatus = actor.getFactionStatus()
if commandString.startswith('imperial') and actorFaction != "imperial":
actor.setFaction('imperial')
return
if commandString.startswith('rebel') and actorFaction != "rebel":
actor.setFaction('rebel')
return
if actorStatus != 0 and actorStatus == 1:
actor.setFactionStatus(2)
actor.sendSystemMessage('@faction_recruiter:overt_complete', 0)
return
if actorStatus == 2:
actor.setFactionStatus(1)
actor.sendSystemMessage('@faction_recruiter:covert_complete', 0)
return
return
+9
View File
@@ -0,0 +1,9 @@
import sys
def setup():
return
def run(core, actor, target, commandString):
playerObject = actor.getSlottedObject('ghost')
playerObject.setTitle(str(commandString))
return
+132
View File
@@ -0,0 +1,132 @@
from resources.objects.creature import CreatureObject
from java.util import Date
from engine.resources.objects import SWGObject
from services.chat import ChatService
from services.chat import Mail
from services.sui import SUIWindow
from services.sui import SUIService
from services.sui.SUIWindow import Trigger
from services.sui.SUIService import MessageBoxType
from java.util import Vector
import sys
# initialize global vars (happens at compile time)
commandArgs = ""
commandLength = 0
actorID = long(0)
targetID = long(0)
tipAmount = 0
tipAmountBank = 0
bankSurcharge = 0
def setup():
return
def run(core, actor, target, commandString):
# set the global variables
global actorID
global targetID
global commandArgs
global commandLength
global tipAmount
global tipAmountBank
global bankSurcharge
actorID = actor.getObjectID()
targetID = target.getObjectID()
commandArgs = commandString.split(" ")
commandLength = len(commandArgs)
tipAmount = commandArgs[0]
tipAmountBank = commandArgs[0]
bankSurcharge = int(0.05) * int(tipAmountBank)
#/tip int || /tip target int
if commandLength == 1:
tipAmount = commandArgs[0]
actorFunds = actor.getCashCredits()
currentTarget = core.objectService.getObject(target.getObjectId())
if (actor.inRange(target.getPosition(), 100)): # 100 = 10m
if int(tipAmount) > 0 and int(tipAmount) <= 1000000:
if actorFunds >= int(tipAmount):
currentTarget.setCashCredits(int(tipAmount))
actor.setCashCredits(actorFunds - int(tipAmount))
currentTarget.sendSystemMessage(actor.getCustomName() + ' tips you ' + tipAmount + ' credits.', 0)
actor.sendSystemMessage('You successfully tip ' + tipAmount + ' credits to ' + currentTarget.getCustomName() + '.', 0)
return
actor.sendSystemMessage('You lack the cash funds to tip ' + tipAmount + ' credits to ' + currentTarget.getCustomName() + '.', 0)
return
actor.sendSystemMessage('Invalid tip amount, set amount between 1 and 1,000,000 credits', 0)
return
actor.sendSystemMessage('Target is too far away. Try a wire bank transfer instead.', 0)
return
#/tip target 30000000 bank
if commandLength == 2:
suiSvc = core.suiService
suiWindow = suiSvc.createMessageBox(MessageBoxType.MESSAGE_BOX_YES_NO, "@base_player:tip_wire_title", "@base_player:tip_wire_prompt", actor, actor, 10)
returnParams = Vector()
returnParams.add('btnOk:Text')
returnParams.add('btnCancel:Text')
suiWindow.addHandler(0, '', Trigger.TRIGGER_OK, returnParams, handleBankTip)
suiWindow.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnParams, handleBankTip)
suiSvc.openSUIWindow(suiWindow)
return
return
def handleBankTip(core, owner, eventType, returnList):
chatSvc = core.chatService
actorGlobal = core.objectService.getObject(actorID)
targetGlobal = core.objectService.getObject(targetID)
actorFunds = actorGlobal.getBankCredits()
totalLost = int(tipAmountBank) + bankSurcharge
if eventType == 0:
if int(totalLost) > actorFunds:
actorGlobal.sendSystemMessage('You do not have ' + str(totalLost) + ' credits (surcharge included) to tip the desired amount to ' + targetGlobal.getCustomName() + '.', 0)
return
if int(tipAmount) > 0 and int(actorFunds) >= int(totalLost):
date = Date()
targetName = targetGlobal.getCustomName()
targetMail = Mail()
targetMail.setMailId(chatSvc.generateMailId())
targetMail.setTimeStamp((int) (date.getTime() / 1000))
targetMail.setRecieverId(targetID)
targetMail.setStatus(Mail.NEW)
targetMail.setMessage(tipAmount + ' credits from ' + actorGlobal.getCustomName() + ' have been successfully delivered from escrow to your bank account')
targetMail.setSubject('@base_player:wire_mail_subject')
targetMail.setSenderName('bank')
actorMail = Mail()
actorMail.setMailId(chatSvc.generateMailId())
actorMail.setRecieverId(actorID)
actorMail.setStatus(Mail.NEW)
actorMail.setTimeStamp((int) (date.getTime() / 1000))
actorMail.setMessage('An amount of ' + tipAmount + ' credits have been transfered from your bank to escrow. It will be delivered to ' +
targetGlobal.getCustomName() + ' as soon as possible.')
actorMail.setSubject('@base_player:wire_mail_subject')
actorMail.setSenderName('bank')
targetGlobal.setBankCredits(int(tipAmount))
actorGlobal.setBankCredits(int(actorFunds) - int(totalLost))
actorGlobal.sendSystemMessage('You have successfully sent ' + tipAmount + ' bank credits to ' + targetGlobal.getCustomName(), 0)
targetGlobal.sendSystemMessage('You have successfully received ' + tipAmount + ' bank credits from ' + actorGlobal.getCustomName(), 0)
chatSvc.storePersistentMessage(actorMail)
chatSvc.storePersistentMessage(targetMail)
chatSvc.sendPersistentMessageHeader(actorGlobal.getClient(), actorMail)
chatSvc.sendPersistentMessageHeader(targetGlobal.getClient(), targetMail)
return
else:
actorGlobal.sendSystemMessage('You lack the bank funds to wire ' + tipAmount + ' bank funds to ' + targetGlobal.getCustomName() + '.', 0)
return
return
+6 -1
View File
@@ -45,6 +45,7 @@ import services.map.MapService;
import services.object.ObjectService;
import services.object.UpdateService;
import services.sui.SUIService;
import services.trade.TradeService;
import engine.clientdata.ClientFileManager;
import engine.clientdata.visitors.CrcStringTableVisitor;
import engine.clientdata.visitors.DatatableVisitor;
@@ -99,6 +100,7 @@ public class NGECore {
public SUIService suiService;
public GuildService guildService;
public GCWService gcwService;
public TradeService tradeService;
// Login Server
public NetworkDispatch loginDispatch;
@@ -178,7 +180,7 @@ public class NGECore {
terrainService.addPlanet(1, "tatooine", "terrain/tatooine.trn", true);
terrainService.loadSnapShotObjects();
// Zone services that need to be loaded after the above
simulationService = new SimulationService(this);
zoneDispatch.addService(simulationService);
@@ -189,6 +191,9 @@ public class NGECore {
gcwService = new GCWService(this);
zoneDispatch.addService(gcwService);
tradeService = new TradeService(this);
zoneDispatch.addService(tradeService);
didServerCrash = false;
System.out.println("Started Server.");
}
@@ -22,7 +22,6 @@
package protocol.swg;
import java.nio.ByteOrder;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.mina.core.buffer.IoBuffer;
File diff suppressed because one or more lines are too long
+40
View File
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg;
import org.apache.mina.core.buffer.IoBuffer;
public class GcwRegionsReq extends SWGMessage {
public GcwRegionsReq() {
}
public void deserialize(IoBuffer buffer) {
}
public IoBuffer serialize() {
return null;
}
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class AbortTradeMessage extends SWGMessage {
@Override
public void deserialize(IoBuffer data) {
data.getShort();
data.getInt();
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 1);
result.putInt(0x9CA80F98);
return result.flip();
}
}
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class AcceptTransactionMessage extends SWGMessage {
@Override
public void deserialize(IoBuffer data) {
data.getShort();
data.getInt();
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 1);
result.putInt(0xB131CA17);
return result.flip();
}
}
@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import main.NGECore;
import org.apache.mina.core.buffer.IoBuffer;
import engine.resources.objects.SWGObject;
import protocol.swg.SWGMessage;
@SuppressWarnings("unused")
public class AddItemMessage extends SWGMessage {
private NGECore core;
private SWGObject tradeObject;
private long tradeObjectID;
@Override
public void deserialize(IoBuffer data) {
data.getShort();
data.getInt();
setTradeObjectID(data.getLong());
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(200).order(ByteOrder.LITTLE_ENDIAN);
result.setAutoExpand(true);
result.putShort((short) 2);
result.putInt(0x1E8D1356);
result.putLong(tradeObjectID);
return result.flip();
}
public long getTradeObjectID() {
return this.tradeObjectID;
}
public SWGObject getTradeObject() {
return this.tradeObject;
}
public void setTradeObject(SWGObject object) {
this.tradeObject = object;
this.tradeObjectID = object.getObjectID();
}
public void setTradeObjectID(long objectID) {
this.tradeObjectID = objectID;
}
}
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class BeginTradeMessage extends SWGMessage {
private long objectId;
public BeginTradeMessage(long objectId) {
this.objectId = objectId;
}
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 2);
result.putInt(0x325932D8);
result.putLong(objectId);
return result.flip();
}
}
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class BeginVerificationMessage extends SWGMessage {
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20);
result.putShort((short) 1);
result.putInt(0xE7491DF5);
return result.flip();
}
}
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class DenyTradeMessage extends SWGMessage {
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 1);
result.putInt(0x6EC28670);
return result.flip();
}
}
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class GiveMoneyMessage extends SWGMessage {
private int credits;
@Override
public void deserialize(IoBuffer data) {
data.getShort();
data.getInt();
setTradingCredits(data.getInt());
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(40).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 2);
result.putInt(0xD1527EE8);
result.putInt(credits);
return result.flip();
}
public int getTradingCredits() {
return this.credits;
}
public void setTradingCredits(int credits) {
this.credits = credits;
}
}
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class RemoveItemMessage extends SWGMessage {
private long objectID;
@Override
public void deserialize(IoBuffer data) {
data.getShort();
data.getInt();
setObjectID(data.getLong());
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 1);
result.putInt(0x4417AF8B);
result.putLong(objectID);
return result.flip();
}
public void setObjectID(long objectID) {
this.objectID = objectID;
}
public long getObjectID() {
return this.objectID;
}
}
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class TradeCompleteMessage extends SWGMessage {
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 1);
result.putInt(0xC542038B);
return result.flip();
}
}
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
public class TradeOpcodes {
public static int AbortTradeMessage = 0x9CA80F98;
public static int TradeCompleteMessage = 0xC542038B;
public static int AddItemMessage = 0x1E8D1356;
public static int RemoveItemMessage = 0x4417AF8B;
public static int GiveMoneyMessage = 0xD1527EE8;
public static int AcceptTransactionMessage = 0xB131CA17;
public static int UnAcceptTransactionMessage = 0xE81E4382;
public static int VerifyTradeMessage = 0x9AE247EE;
public static int AddItemFailedMessage = 0x69D3E1D2;
public static int BeginVerificationMessage = 0xE7491DF5;
}
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class UnAcceptTransactionMessage extends SWGMessage {
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 1);
result.putInt(0xE81E4382);
return result.flip();
}
}
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package protocol.swg.clientSecureTradeManager;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.SWGMessage;
public class VerifyTradeMessage extends SWGMessage {
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(20).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 1);
result.putInt(0x9AE247EE);
return result.flip();
}
}
@@ -0,0 +1,59 @@
package protocol.swg.objectControllerObjects;
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import protocol.swg.ObjControllerMessage;
public class SecureTrade extends ObjControllerObject{
private long senderID;
private long recieverID;
private short unknown;
public SecureTrade() {
}
@Override
public void deserialize(IoBuffer data) {
setSenderID(data.getLong());
data.getLong(); // skip through 0's
data.getLong(); // skip through 0's
setRecieverID(data.getLong());
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN);
result.setAutoExpand(true);
result.putInt(ObjControllerMessage.SPACIAL_CHAT);
result.putInt(1);
result.putLong(senderID);
result.putLong(0);
result.putLong(0);
result.putLong(recieverID);
return result.flip();
}
public long getSenderID() { return this.senderID; }
public long getRecieverID() { return this.recieverID; }
public short getUnkn() { return this.unknown; }
public void setUnknown(short unknown) {
this.unknown = unknown;
}
public void setSenderID(long senderID) {
this.senderID = senderID;
}
public void setRecieverID(long recieverID) {
this.recieverID = recieverID;
}
}
@@ -28,5 +28,6 @@ public class ObjControllerOpcodes {
public static final int COMMAND_QUEUE_ENQUEUE = 0x16010000;
public static final int TARGET_UPDATE = 0x26010000;
public static final int OBJECT_MENU_REQUEST = 0x46010000;
public static final int SECURE_TRADE = 0x15010000;
}
+8 -1
View File
@@ -21,6 +21,8 @@
******************************************************************************/
package resources.common;
import engine.resources.common.CRC;
public class Opcodes {
public static int ChatDeletePersistentMessage = 0x8F251641;
@@ -43,5 +45,10 @@ public class Opcodes {
public static int RequestGalaxyLoopTimes = 0x7D842D68;
public static int SelectCharacter = 0xB5098D76;
public static int SuiEventNotification = 0x092D3564;
public static int DeltasMessage = 0x12862153;
public static int ChatAddFriend = 0x6FE7BD90;
public static int GcwRegionsReq = 0x7C8C8E0E; //CRC.StringtoCRC("GcwRegionsReq");
public static int GcwRegionsRsp = 0x8DCAB70C; //CRC.StringtoCRC("GcwRegionsRsp");
public static int GcwGroupsRsp = CRC.StringtoCRC("GcwGroupsRsp");
}
+92
View File
@@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.common;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class StringUtilities {
public static String getAsciiString(ByteBuffer buffer) {
return getString(buffer, "US-ASCII");
}
public static String getUnicodeString(ByteBuffer buffer) {
return getString(buffer, "UTF-16LE");
}
public static byte[] getAsciiString(String string) {
return getString(string, "US-ASCII");
}
public static byte[] getUnicodeString(String string) {
return getString(string, "UTF-16LE");
}
private static String getString(ByteBuffer buffer, String charFormat) {
String result;
int length;
if (charFormat == "UTF-16LE") {
length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt();
} else {
length = buffer.order(ByteOrder.LITTLE_ENDIAN).getShort();
}
int bufferPosition = buffer.position();
try {
result = new String(buffer.array(), bufferPosition, length, charFormat);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "";
}
buffer.position(bufferPosition + length);
return result;
}
private static byte[] getString(String string, String charFormat) {
ByteBuffer result;
int length = 2 + string.length();
if (charFormat == "UTF-16LE") {
result = ByteBuffer.allocate(length * 2).order(ByteOrder.LITTLE_ENDIAN);
result.putInt(string.length());
} else {
result = ByteBuffer.allocate(length).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short)string.length());
}
try {
result.put(string.getBytes(charFormat));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return new byte[] { };
}
return result.array();
}
}
@@ -21,54 +21,71 @@
******************************************************************************/
package resources.objects;
public class CurrentServerGCWZoneInfo {
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
public class CurrentServerGCWZoneHistory extends ListObject {
private byte unknown1 = 0;
private String zone = "";
private int unknown2 = 0x0D05EA4E;
private int lastUpdateTime = ((int) System.currentTimeMillis());
private int percent = 50;
public CurrentServerGCWZoneInfo(byte unknown1, String zone, int unknown2, int percent) {
this.unknown1 = unknown1;
public CurrentServerGCWZoneHistory(String zone, int percent) {
this.zone = zone;
this.unknown2 = unknown2;
this.percent = percent;
}
public CurrentServerGCWZoneInfo(String zone) {
public CurrentServerGCWZoneHistory(String zone) {
this.zone = zone;
}
public byte getUnknown1() {
return unknown1;
synchronized(objectMutex) {
return unknown1;
}
}
public void setUnknown1(byte unknown1) {
this.unknown1 = unknown1;
synchronized(objectMutex) {
this.unknown1 = unknown1;
}
}
public String getZone() {
return zone;
synchronized(objectMutex) {
return zone;
}
}
public void setZone(String zone) {
this.zone = zone;
}
public int getUnknown2() {
return unknown2;
}
public void setUnknown2(int unknown2) {
this.unknown2 = unknown2;
public int getLastUpdateTime() {
synchronized(objectMutex) {
return lastUpdateTime;
}
}
public int getPercent() {
return percent;
synchronized(objectMutex) {
return percent;
}
}
public void setPercent(int percent) {
this.percent = percent;
synchronized(objectMutex) {
this.percent = percent;
this.lastUpdateTime = ((int) System.currentTimeMillis());
}
}
public byte[] getBytes() {
synchronized(objectMutex) {
IoBuffer buffer = bufferPool.allocate((8 + zone.length() + 2), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getAsciiString(zone));
buffer.putInt(lastUpdateTime);
buffer.putInt(percent);
return buffer.array();
}
}
}
@@ -21,44 +21,97 @@
******************************************************************************/
package resources.objects;
public class CurrentServerGCWZonePercent {
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
public class CurrentServerGCWZonePercent extends ListObject {
private byte unknown = 0;
private byte unknown1 = 0;
private String zone = "";
private int percent = 50;
public CurrentServerGCWZonePercent(byte unknown, String zone, int percent) {
this.unknown = unknown;
this.zone = zone;
this.percent = percent;
}
private int percent = 60;
private int gcwPoints = 0;
public CurrentServerGCWZonePercent(String zone) {
this.zone = zone;
}
public byte getUnknown() {
return unknown;
public byte getUnknown1() {
synchronized(objectMutex) {
return unknown1;
}
}
public void setUnknown(byte unknown) {
this.unknown = unknown;
public void setUnknown1(byte unknown1) {
synchronized(objectMutex) {
this.unknown1 = unknown1;
}
}
public String getZone() {
return zone;
}
public void setZone(String zone) {
this.zone = zone;
synchronized(objectMutex) {
return zone;
}
}
public int getPercent() {
return percent;
synchronized(objectMutex) {
return percent;
}
}
public void setPercent(int percent) {
this.percent = percent;
public void setPercent(int percent, SWGList<CurrentServerGCWZoneHistory> historyList) {
synchronized(objectMutex) {
int historyCount = 0;
int firstHistoryIndex = historyList.get().size();
int lastHistoryIndex = historyList.get().size();
for (int i = 0; i < historyList.size(); i++) {
if (historyList.get(i).getZone() == getZone()) {
historyCount++;
lastHistoryIndex = i;
if (historyCount == 1) {
firstHistoryIndex = i;
}
}
}
if (historyCount > 10) {
historyList.remove(firstHistoryIndex);
}
historyList.add(lastHistoryIndex, new CurrentServerGCWZoneHistory(zone, percent));
this.percent = percent;
}
}
public int getGCWPoints() {
synchronized(objectMutex) {
return gcwPoints;
}
}
public void addGCWPoints(int gcwPoints) {
synchronized(objectMutex) {
this.gcwPoints += gcwPoints;
}
}
public void removeGCWPoints(int gcwPoints) {
synchronized(objectMutex) {
this.gcwPoints = (((this.gcwPoints - gcwPoints) < 0) ? 0 : this.gcwPoints - gcwPoints);
}
}
public byte[] getBytes() {
synchronized(objectMutex) {
IoBuffer buffer = bufferPool.allocate((4 + zone.length() + 2), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getAsciiString(zone));
buffer.putInt(percent);
return buffer.array();
}
}
}
+54 -9
View File
@@ -21,44 +21,89 @@
******************************************************************************/
package resources.objects;
public class Guild {
import java.nio.ByteOrder;
import java.util.List;
import org.apache.mina.core.buffer.IoBuffer;
import engine.resources.objects.SWGObject;
public class Guild extends ListObject {
private int id;
private String abbreviation;
private String name;
private SWGObject leader;
private List<SWGObject> members;
public Guild(int id, String abbreviation, String name) {
public Guild(int id, String abbreviation, String name, SWGObject leader) {
this.id = id;
this.abbreviation = abbreviation;
this.name = name;
this.leader = leader;
this.members.add(leader);
}
public int getId() {
return id;
synchronized(objectMutex) {
return id;
}
}
public void setId(int id) {
this.id = id;
synchronized(objectMutex) {
this.id = id;
}
}
public String getAbbreviation() {
return abbreviation;
synchronized(objectMutex) {
return abbreviation;
}
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
synchronized(objectMutex) {
this.abbreviation = abbreviation;
}
}
public String getName() {
return name;
synchronized(objectMutex) {
return name;
}
}
public void setName(String name) {
this.name = name;
synchronized(objectMutex) {
this.name = name;
}
}
public String getString() {
return (Integer.toString(id) + ":" + abbreviation);
synchronized(objectMutex) {
return (Integer.toString(id) + ":" + abbreviation);
}
}
public SWGObject getLeader() {
return leader;
}
public void setLeader(SWGObject leader) {
this.leader = leader;
}
public List<SWGObject> getMembers() {
return members;
}
public byte[] getBytes() {
synchronized(objectMutex) {
IoBuffer buffer = bufferPool.allocate((getString().length() + 2), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getAsciiString(getString()));
return buffer.array();
}
}
}
@@ -19,8 +19,10 @@
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.objects.group;
public class GroupMessageBuilder {
package resources.objects;
public interface IListObject {
public byte[] getBytes();
}
+51
View File
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.objects;
import java.nio.ByteBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator;
import resources.common.StringUtilities;
public abstract class ListObject implements IListObject {
protected final Object objectMutex = new Object();
public SimpleBufferAllocator bufferPool = new SimpleBufferAllocator();
protected String getAsciiString(ByteBuffer buffer) {
return StringUtilities.getAsciiString(buffer);
}
protected String getUnicodeString(ByteBuffer buffer) {
return StringUtilities.getUnicodeString(buffer);
}
protected byte[] getAsciiString(String string) {
return StringUtilities.getAsciiString(string);
}
protected byte[] getUnicodeString(String string) {
return StringUtilities.getUnicodeString(string);
}
}
+57 -25
View File
@@ -28,6 +28,8 @@ import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator;
import resources.common.Opcodes;
import engine.resources.objects.SWGObject;
public abstract class ObjectMessageBuilder {
@@ -36,49 +38,79 @@ public abstract class ObjectMessageBuilder {
public SimpleBufferAllocator bufferPool = new SimpleBufferAllocator();
public IoBuffer createBaseline(String objectType, byte viewType, IoBuffer data, int size) {
IoBuffer buffer = bufferPool.allocate(23 + size, false).order(ByteOrder.LITTLE_ENDIAN);
IoBuffer buf = bufferPool.allocate(23 + size, false).order(ByteOrder.LITTLE_ENDIAN);
buf.putShort((short) 5);
buf.putInt(0x68A75F0C);
buf.putLong(object.getObjectID());
buffer.putShort((short) 5);
buffer.putInt(0x68A75F0C);
buffer.putLong(object.getObjectID());
try {
buf.put(reverse(objectType).getBytes("US-ASCII"));
buffer.put(reverse(objectType).getBytes("US-ASCII"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
buf.put(viewType);
buf.putInt(size); // size
buf.put(data);
buf.flip();
return buf;
buffer.put(viewType);
buffer.putInt(size);
buffer.put(data);
buffer.flip();
return buffer;
}
public IoBuffer createDelta(String objectType, byte viewType, short updateCount, short updateType, IoBuffer data, int size) {
IoBuffer buffer = bufferPool.allocate(27 + size, false).order(ByteOrder.LITTLE_ENDIAN);
IoBuffer buf = bufferPool.allocate(27 + size, false).order(ByteOrder.LITTLE_ENDIAN);
buf.putShort((short) 5);
buf.putInt(0x12862153);
buf.putLong(object.getObjectID());
buffer.putShort((short) 5);
buffer.putInt(Opcodes.DeltasMessage);
buffer.putLong(object.getObjectID());
try {
buf.put(reverse(objectType).getBytes("US-ASCII"));
buffer.put(reverse(objectType).getBytes("US-ASCII"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
buf.put(viewType);
buf.putInt(size); // size
buf.putShort(updateCount);
buf.putShort(updateType);
buf.put(data);
buf.flip();
return buf;
buffer.put(viewType);
buffer.putInt(size);
buffer.putShort(updateCount);
buffer.putShort(updateType);
buffer.put(data);
buffer.flip();
return buffer;
}
public IoBuffer createDelta(String objectType, byte viewType, short updateCount, IoBuffer data, int size) {
IoBuffer buffer = bufferPool.allocate(25 + size, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) 5);
buffer.putInt(Opcodes.DeltasMessage);
buffer.putLong(object.getObjectID());
try {
buffer.put(reverse(objectType).getBytes("US-ASCII"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
buffer.put(viewType);
buffer.putInt(size);
buffer.putShort(updateCount);
buffer.put(data);
buffer.flip();
return buffer;
}
public IoBuffer createDeltaObject(short updateType, IoBuffer data, int size) {
IoBuffer buffer = bufferPool.allocate(2 + size, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort(updateType);
buffer.put(data.array());
return buffer;
}
public SWGObject getObject() { return object; }
public void setObject(SWGObject object) { this.object = object; }
public abstract void sendListDelta(byte viewType, short updateType, IoBuffer buffer);
public abstract void sendBaselines();
private String reverse(String reverseString) {
@@ -112,6 +144,7 @@ public abstract class ObjectMessageBuilder {
return result;
}
private byte[] getString(String string, String charFormat) {
ByteBuffer result;
int length = 2 + string.length();
@@ -132,5 +165,4 @@ public abstract class ObjectMessageBuilder {
return result.array();
}
}
@@ -21,54 +21,101 @@
******************************************************************************/
package resources.objects;
public class OtherServerGCWZonePercent {
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
public class OtherServerGCWZonePercent extends ListObject {
private byte unknown = 0;
private byte unknown1 = 0;
private String server = "SWG";
private String zone = "";
private int lastUpdateTime = ((int) System.currentTimeMillis());
private int percent = 50;
public OtherServerGCWZonePercent(byte unknown, String server, String zone, int percent) {
this.unknown = unknown;
private int gcwPoints = 0;
public OtherServerGCWZonePercent(String server, String zone) {
this.server = server;
this.zone = zone;
this.percent = percent;
}
public OtherServerGCWZonePercent(String zone) {
this.zone = zone;
}
public byte getUnknown() {
return unknown;
public OtherServerGCWZonePercent() {
}
public void setUnknown(byte unknown) {
this.unknown = unknown;
public byte getUnknown1() {
synchronized(objectMutex) {
return unknown1;
}
}
public void setUnknown1(byte unknown1) {
synchronized(objectMutex) {
this.unknown1 = unknown1;
}
}
public String getServer() {
return server;
}
public void setServer(String server) {
this.server = server;
synchronized(objectMutex) {
return server;
}
}
public String getZone() {
return zone;
synchronized(objectMutex) {
return zone;
}
}
public void setZone(String zone) {
this.zone = zone;
public int getLastUpdateTime() {
synchronized(objectMutex) {
return lastUpdateTime;
}
}
public int getPercent() {
return percent;
synchronized(objectMutex) {
return percent;
}
}
public void setPercent(int percent) {
this.percent = percent;
synchronized(objectMutex) {
this.percent = percent;
this.lastUpdateTime = ((int) System.currentTimeMillis());
}
}
public int getGCWPoints() {
synchronized(objectMutex) {
return gcwPoints;
}
}
public void addGCWPoints(int gcwPoints) {
synchronized(objectMutex) {
this.gcwPoints += gcwPoints;
}
}
public void removeGCWPoints(int gcwPoints) {
synchronized(objectMutex) {
this.gcwPoints = (((this.gcwPoints - gcwPoints) < 0) ? 0 : this.gcwPoints - gcwPoints);
}
}
public byte[] getBytes() {
synchronized(objectMutex) {
IoBuffer buffer = bufferPool.allocate((4 + server.length() + zone.length() + 4), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getAsciiString(server));
buffer.put(getAsciiString(zone));
buffer.putInt(percent);
return buffer.array();
}
}
}
+359
View File
@@ -0,0 +1,359 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.objects;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.apache.mina.core.buffer.IoBuffer;
import com.sleepycat.persist.model.NotPersistent;
/* A SWGList element MUST implement IListObject, or it will refuse to work with it */
public class SWGList<E> implements List<E> {
private List<E> list = new ArrayList<E>();
@NotPersistent
private int updateCounter;
private ObjectMessageBuilder messageBuilder;
private byte viewType;
private short updateType;
protected final Object objectMutex = new Object();
public SWGList(ObjectMessageBuilder messageBuilder, int viewType, int updateType) {
this.messageBuilder = messageBuilder;
this.viewType = (byte) viewType;
this.updateType = (short) updateType;
}
public boolean add(E e) {
synchronized(objectMutex) {
if (e instanceof IListObject) {
if (list.add(e)) {
queue(item(1, list.lastIndexOf(e), ((IListObject) e).getBytes(), true, true));
return true;
}
}
return false;
}
}
public void add(int index, E element) {
synchronized(objectMutex) {
if (element instanceof IListObject) {
list.add(index, element);
queue(item(1, index, ((IListObject) element).getBytes(), true, true));
}
}
}
public boolean addAll(Collection<? extends E> c) {
synchronized(objectMutex) {
if (!c.isEmpty()) {
List<byte[]> buffer = new ArrayList<byte[]>();
boolean success = false;
for (E element : c) {
if (element instanceof IListObject) {
if (list.add(element)) {
buffer.add(item(1, list.lastIndexOf(element), ((IListObject) element).getBytes(), true, true));
success = true;
}
} else {
return false;
}
}
if (success == true) {
queue(buffer);
} else {
return false;
}
}
return false;
}
}
public boolean addAll(int index, Collection<? extends E> c) {
synchronized(objectMutex) {
if (!c.isEmpty()) {
List<byte[]> buffer = new ArrayList<byte[]>();
for (E element : c) {
if (element instanceof IListObject) {
list.add(index, element);
buffer.add(item(1, index, ((IListObject) element).getBytes(), true, true));
index++;
} else {
return false;
}
}
queue(buffer);
return true;
}
return false;
}
}
public void clear() {
synchronized(objectMutex) {
list.clear();
queue(item(4, 0, null, false, false));
}
}
public boolean contains(Object o) {
synchronized(objectMutex) {
return list.contains(o);
}
}
public boolean containsAll(Collection<?> c) {
synchronized(objectMutex) {
return list.containsAll(c);
}
}
public E get(int index) {
synchronized(objectMutex) {
return list.get(index);
}
}
public List<E> get() {
synchronized(objectMutex) {
return list;
}
}
public int indexOf(Object o) {
synchronized(objectMutex) {
return list.indexOf(o);
}
}
public boolean isEmpty() {
synchronized(objectMutex) {
return list.isEmpty();
}
}
public Iterator<E> iterator() {
synchronized(objectMutex) {
return list.iterator();
}
}
public int lastIndexOf(Object o) {
synchronized(objectMutex) {
return list.lastIndexOf(o);
}
}
public ListIterator<E> listIterator() {
synchronized(objectMutex) {
return list.listIterator();
}
}
public ListIterator<E> listIterator(int index) {
synchronized(objectMutex) {
return listIterator(index);
}
}
public boolean remove(Object o) {
synchronized(objectMutex) {
int index = list.indexOf(o);
if (list.remove(o)) {
queue(item(1, index, null, true, false));
return true;
} else {
return false;
}
}
}
public E remove(int index) {
synchronized(objectMutex) {
E element = list.remove(index);
queue(item(1, index, null, true, false));
return (E) element;
}
}
public boolean removeAll(Collection<?> c) {
synchronized(objectMutex) {
if (!c.isEmpty()) {
List<byte[]> buffer = new ArrayList<byte[]>();
int index;
boolean success = false;
for (Object element : c) {
index = list.indexOf(element);
if (list.remove(element)) {
buffer.add(item(0, index, null, true, false));
success = true;
}
}
if (success) {
queue(buffer);
}
return success;
}
return false;
}
}
public boolean retainAll(Collection<?> c) {
synchronized(objectMutex) {
return list.retainAll(c);
}
}
public E set(int index, E element) {
synchronized(objectMutex) {
if (element instanceof IListObject) {
E previousElement = list.set(index, element);
queue(item(2, index, ((IListObject) element).getBytes(), true, true));
return previousElement;
}
return null;
}
}
public boolean set(List<E> list) {
synchronized(objectMutex) {
byte[] newListData = { 0x03 };
if (!list.isEmpty()) {
for (E element : list) {
if (element instanceof IListObject) {
IoBuffer buffer = messageBuilder.bufferPool.allocate((newListData.length + ((IListObject) element).getBytes().length), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(newListData);
buffer.put(((IListObject) element).getBytes());
newListData = buffer.array();
} else {
return false;
}
}
this.list = list;
updateCounter++;
queue(newListData);
return true;
}
return false;
}
}
public int size() {
synchronized(objectMutex) {
return list.size();
}
}
public List<E> subList(int fromIndex, int toIndex) {
synchronized(objectMutex) {
return list.subList(fromIndex, toIndex);
}
}
public Object[] toArray() {
synchronized(objectMutex) {
return list.toArray();
}
}
public <T> T[] toArray(T[] a) {
synchronized(objectMutex) {
return list.toArray(a);
}
}
public int getUpdateCounter() {
return updateCounter;
}
private byte[] item(int type, int index, byte[] data, boolean useIndex, boolean useData) {
int size = 1 + ((useIndex) ? 2 : 0) + ((useData) ? data.length : 0);
IoBuffer buffer = messageBuilder.bufferPool.allocate((size), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) type);
if (useIndex) buffer.putShort((short) index);
if (useData) buffer.put(data);
updateCounter++;
return buffer.array();
}
private void queue(byte[] data) {
IoBuffer buffer = messageBuilder.bufferPool.allocate((data.length + 8), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(1);
buffer.putInt(updateCounter);
buffer.put(data);
messageBuilder.sendListDelta(viewType, updateType, buffer);
}
private void queue(List<byte[]> data) {
int size = 0;
for (byte[] queued : data) {
size += queued.length;
}
IoBuffer buffer = messageBuilder.bufferPool.allocate((size + 8), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(data.size());
buffer.putInt(updateCounter);
for (byte[] queued : data) buffer.put(queued);
messageBuilder.sendListDelta(viewType, updateType, buffer);
}
}
+185
View File
@@ -0,0 +1,185 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.objects;
import java.nio.ByteOrder;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.mina.core.buffer.IoBuffer;
import resources.common.StringUtilities;
import com.sleepycat.persist.model.NotPersistent;
@SuppressWarnings("unused")
public class SWGMap<K, V> implements Map<K, V> {
private Map<K, V> map = new TreeMap<K, V>();
@NotPersistent
private int updateCounter;
private ObjectMessageBuilder messageBuilder;
private byte viewType;
private short updateType;
protected final Object objectMutex = new Object();
public SWGMap(ObjectMessageBuilder messageBuilder, int viewType, int updateType) {
this.messageBuilder = messageBuilder;
this.viewType = (byte) viewType;
this.updateType = (short) updateType;
}
public void clear() {
throw new UnsupportedOperationException();
}
public boolean containsKey(Object key) {
synchronized(objectMutex) {
return map.containsKey(key);
}
}
public boolean containsValue(Object value) {
synchronized(objectMutex) {
return map.containsValue(value);
}
}
public Set<java.util.Map.Entry<K, V>> entrySet() {
synchronized(objectMutex) {
return map.entrySet();
}
}
public V get(Object key) {
synchronized(objectMutex) {
return map.get(key);
}
}
public boolean isEmpty() {
synchronized(objectMutex) {
return map.isEmpty();
}
}
public Set<K> keySet() {
synchronized(objectMutex) {
return map.keySet();
}
}
public V put(K key, V value) {
synchronized(objectMutex) {
if (key instanceof String && value instanceof IListObject) {
if (map.containsKey(key)) {
// Changing an existing map
V oldValue = map.put(key, value);
queue(item(2, key, ((IListObject) value).getBytes(), true, true));
return oldValue;
} else {
// Adding to the map
V oldValue = map.put(key, value);
queue(item(0, key, ((IListObject) value).getBytes(), true, true));
return oldValue;
}
}
return null;
}
}
public void putAll(Map<? extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}
public V remove(Object arg0) {
throw new UnsupportedOperationException();
}
public int size() {
synchronized(objectMutex) {
return map.size();
}
}
public Collection<V> values() {
synchronized(objectMutex) {
return map.values();
}
}
public int getUpdateCounter() {
return updateCounter;
}
private byte[] item(int type, K index, byte[] data, boolean useIndex, boolean useData) {
if (index instanceof String) {
int size = 1 + ((useIndex) ? (2 + ((String) index).getBytes().length) : 0) + ((useData) ? data.length : 0);
IoBuffer buffer = messageBuilder.bufferPool.allocate((size), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) type);
if (useIndex) buffer.put(((index instanceof String) ? StringUtilities.getAsciiString((String) index) : Integer.toString(0).getBytes()));
if (useData) buffer.put(data);
updateCounter++;
return buffer.array();
} else {
throw new IllegalArgumentException();
}
}
private void queue(byte[] data) {
IoBuffer buffer = messageBuilder.bufferPool.allocate((data.length + 8), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(1);
buffer.putInt(updateCounter);
buffer.put(data);
messageBuilder.sendListDelta(viewType, updateType, buffer);
}
private void queue(List<byte[]> data) {
int size = 0;
for (byte[] queued : data) {
size += queued.length;
}
IoBuffer buffer = messageBuilder.bufferPool.allocate((size + 8), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(data.size());
buffer.putInt(updateCounter);
for (byte[] queued : data) buffer.put(queued);
messageBuilder.sendListDelta(viewType, updateType, buffer);
}
}
@@ -593,13 +593,16 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
// TODO Auto-generated method stub
}
@Override
public void sendBaselines() {
}
}
@@ -22,17 +22,21 @@
package resources.objects.guild;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import org.apache.mina.core.buffer.IoBuffer;
import resources.objects.CurrentServerGCWZoneInfo;
import resources.objects.CurrentServerGCWZoneHistory;
import resources.objects.CurrentServerGCWZonePercent;
import resources.objects.Guild;
import resources.objects.ObjectMessageBuilder;
import resources.objects.OtherServerGCWZonePercent;
public class GuildMessageBuilder extends ObjectMessageBuilder {
private List<IoBuffer> zoneUpdates = new ArrayList<IoBuffer>();
public GuildMessageBuilder(GuildObject guildObject) {
setObject(guildObject);
}
@@ -49,8 +53,8 @@ public class GuildMessageBuilder extends ObjectMessageBuilder {
buffer.put(getUnicodeString(guilds.getCustomName()));
buffer.putInt(guilds.getVolume());
buffer.putInt(guilds.getGuildList().size());
buffer.putInt(guilds.getGuildListUpdateCounter());
for (Guild object : guilds.getGuildList()) {
buffer.putInt(guilds.getGuildList().getUpdateCounter());
for (Guild object : guilds.getGuildList().get()) {
buffer.put(getAsciiString(object.getString()));
}
@@ -66,11 +70,10 @@ public class GuildMessageBuilder extends ObjectMessageBuilder {
GuildObject guilds = (GuildObject) object;
int capacity = 82;
//int capacity = 77;
capacity += (guilds.getCurrentServerGCWZonePercentList().size() * 30);
capacity += (guilds.getCurrentServerGCWTotalPercentList().size() * 14);
capacity += (guilds.getCurrentServerGCWZoneInfoList().size() * 34);
capacity += (guilds.getCurrentServerGCWTotalInfoList().size() * 18);
capacity += (guilds.getCurrentServerGCWZoneHistoryList().size() * 34);
capacity += (guilds.getCurrentServerGCWTotalHistoryList().size() * 18);
capacity += (guilds.getOtherServerGCWZonePercentList().size() * 45);
capacity += (guilds.getOtherServerGCWTotalPercentList().size() * 29);
@@ -81,52 +84,52 @@ public class GuildMessageBuilder extends ObjectMessageBuilder {
buffer.putInt(guilds.getUnknown1());
buffer.putShort(guilds.getUnknown2());
buffer.putInt(guilds.getCurrentServerGCWZonePercentList().size());
buffer.putInt(guilds.getCurrentServerGCWZonePercentListUpdateCounter());
for (CurrentServerGCWZonePercent object : guilds.getCurrentServerGCWZonePercentList()) {
buffer.put(object.getUnknown());
buffer.putInt(guilds.getCurrentServerGCWZonePercentList().getUpdateCounter());
for (CurrentServerGCWZonePercent object : guilds.getCurrentServerGCWZonePercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getCurrentServerGCWTotalPercentList().size());
buffer.putInt(guilds.getCurrentServerGCWTotalPercentListUpdateCounter());
for (CurrentServerGCWZonePercent object : guilds.getCurrentServerGCWTotalPercentList()) {
buffer.put(object.getUnknown());
buffer.putInt(guilds.getCurrentServerGCWTotalPercentList().getUpdateCounter());
for (CurrentServerGCWZonePercent object : guilds.getCurrentServerGCWTotalPercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getCurrentServerGCWZoneInfoList().size());
buffer.putInt(guilds.getCurrentServerGCWZoneInfoListUpdateCounter());
for (CurrentServerGCWZoneInfo object : guilds.getCurrentServerGCWZoneInfoList()) {
buffer.putInt(guilds.getCurrentServerGCWZoneHistoryList().size());
buffer.putInt(guilds.getCurrentServerGCWZoneHistoryList().getUpdateCounter());
for (CurrentServerGCWZoneHistory object : guilds.getCurrentServerGCWZoneHistoryList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getUnknown2());
buffer.putInt(object.getLastUpdateTime());
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getCurrentServerGCWTotalInfoList().size());
buffer.putInt(guilds.getCurrentServerGCWTotalInfoListUpdateCounter());
for (CurrentServerGCWZoneInfo object : guilds.getCurrentServerGCWTotalInfoList()) {
buffer.putInt(guilds.getCurrentServerGCWTotalHistoryList().size());
buffer.putInt(guilds.getCurrentServerGCWTotalHistoryList().getUpdateCounter());
for (CurrentServerGCWZoneHistory object : guilds.getCurrentServerGCWTotalHistoryList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getUnknown2());
buffer.putInt(object.getLastUpdateTime());
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getOtherServerGCWZonePercentList().size());
buffer.putInt(guilds.getOtherServerGCWZonePercentListUpdateCounter());
for (OtherServerGCWZonePercent object : guilds.getOtherServerGCWZonePercentList()) {
buffer.put(object.getUnknown());
buffer.putInt(guilds.getOtherServerGCWZonePercentList().getUpdateCounter());
for (OtherServerGCWZonePercent object : guilds.getOtherServerGCWZonePercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getServer()));
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(guilds.getOtherServerGCWTotalPercentList().size());
buffer.putInt(guilds.getOtherServerGCWTotalPercentListUpdateCounter());
for (OtherServerGCWZonePercent object : guilds.getOtherServerGCWTotalPercentList()) {
buffer.put(object.getUnknown());
buffer.putInt(guilds.getOtherServerGCWTotalPercentList().getUpdateCounter());
for (OtherServerGCWZonePercent object : guilds.getOtherServerGCWTotalPercentList().get()) {
buffer.put(object.getUnknown1());
buffer.put(getAsciiString(object.getServer()));
buffer.put(getAsciiString(object.getZone()));
buffer.putInt(object.getPercent());
}
buffer.putInt(5); // Unknown
buffer.putInt(guilds.getUnknown3());
int size = buffer.position();
buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);
@@ -136,10 +139,174 @@ public class GuildMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
public IoBuffer buildComplexity(float complexity) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putFloat(complexity);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 0, buffer, size + 4);
return buffer;
}
public IoBuffer buildSTF(String STFFile, int STFSpacer, String STFName) {
IoBuffer buffer = bufferPool.allocate((STFFile.length() + STFName.length() + 8), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getAsciiString(STFFile));
buffer.putInt(STFSpacer);
buffer.put(getAsciiString(STFName));
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 1, buffer, size + 4);
return buffer;
}
public IoBuffer buildCustomName(String customName) {
IoBuffer buffer = bufferPool.allocate((customName.length() + 4), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getUnicodeString(customName));
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 2, buffer, size + 4);
return buffer;
}
public IoBuffer buildVolume(int volume) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(volume);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 3, buffer, size + 4);
return buffer;
}
public IoBuffer buildServerId(int serverId) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(serverId);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 6, (short) 1, (short) 0, buffer, size + 4);
return buffer;
}
public IoBuffer buildUnknowns(int unknown1, short unknown2) {
IoBuffer buffer = bufferPool.allocate(6, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(unknown1);
buffer.putShort(unknown2);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 6, (short) 1, (short) 1, buffer, size + 4);
return buffer;
}
public IoBuffer buildGCWDelta() {
synchronized(zoneUpdates) {
if (zoneUpdates.size() > 0) {
int updates = zoneUpdates.size();
int size = 4;
for (int i = 0; i < zoneUpdates.size(); i++) {
size += zoneUpdates.get(i).position();
}
IoBuffer buffer = bufferPool.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < zoneUpdates.size(); i++) {
buffer.put(zoneUpdates.get(i).array());
}
zoneUpdates.clear();
buffer.flip();
return createDelta("GILD", (byte) 6, (short) updates, buffer, size);
} else {
return null;
}
}
}
public IoBuffer buildUnknown3(int unknown3) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(unknown3);
int size = buffer.position();
buffer.flip();
buffer = createDelta("GILD", (byte) 6, (short) 1, (short) 8, buffer, size + 4);
return buffer;
}
final protected static char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
int v;
for ( int j = 0; j < bytes.length; j++ ) {
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
synchronized(zoneUpdates) {
switch (viewType) {
case 3:
{
switch (updateType) {
case 4:
{
buffer.flip();
buffer = createDelta("GILD", (byte) 3, (short) 1, (short) 4, buffer, buffer.position() + 4);
for (int i = 0; i < ((GuildObject) object).core.getActiveConnectionsMap().size(); i++) {
((GuildObject) object).core.getActiveConnectionsMap().get(i).getSession().write(buffer);
}
break;
}
}
}
case 6:
{
switch (updateType) {
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
{
buffer = createDeltaObject(updateType, buffer, buffer.position());
//System.out.println("Packet: " + bytesToHex(buffer.array()));
zoneUpdates.add(buffer);
break;
}
default:
{
return;
}
}
}
}
}
}
@Override
public void sendBaselines() {
// TODO Auto-generated method stub
}
}
+75 -121
View File
@@ -21,13 +21,15 @@
******************************************************************************/
package resources.objects.guild;
import java.util.ArrayList;
import java.util.List;
import org.apache.mina.core.buffer.IoBuffer;
import resources.objects.CurrentServerGCWZoneInfo;
import main.NGECore;
import resources.objects.CurrentServerGCWZoneHistory;
import resources.objects.CurrentServerGCWZonePercent;
import resources.objects.Guild;
import resources.objects.OtherServerGCWZonePercent;
import resources.objects.SWGList;
import com.sleepycat.persist.model.NotPersistent;
@@ -39,6 +41,10 @@ import engine.resources.scene.Quaternion;
public class GuildObject extends SWGObject {
protected NGECore core;
@NotPersistent
private GuildMessageBuilder messageBuilder = new GuildMessageBuilder(this);
// GILD 3
private float complexity = 0x803F0F00;
private String STFFile = "string_id_table";
@@ -46,46 +52,24 @@ public class GuildObject extends SWGObject {
private String STFName = "";
private String customName = "";
private int volume = 0;
private List<Guild> guildList = new ArrayList<Guild>();
@NotPersistent
private int guildListUpdateCounter = 0;
private SWGList<Guild> guildList = new SWGList<Guild>(messageBuilder, 3, 4);
// GILD 6
private int serverId = 0x00000041;
//private String STFName = "string_id_table";
private int unknown1 = 0;
private short unknown2 = 0;
private List<CurrentServerGCWZonePercent> currentServerGCWZonePercentList = new ArrayList<CurrentServerGCWZonePercent>();
@NotPersistent
private int currentServerGCWZonePercentListUpdateCounter = 0;
private List<CurrentServerGCWZonePercent> currentServerGCWTotalPercentList = new ArrayList<CurrentServerGCWZonePercent>();
@NotPersistent
private int currentServerGCWTotalPercentListUpdateCounter = 0;
private List<CurrentServerGCWZoneInfo> currentServerGCWZoneInfoList = new ArrayList<CurrentServerGCWZoneInfo>();
@NotPersistent
private int currentServerGCWZoneInfoListUpdateCounter = 0;
private SWGList<CurrentServerGCWZonePercent> currentServerGCWZonePercentList = new SWGList<CurrentServerGCWZonePercent>(messageBuilder, 6, 2);
private SWGList<CurrentServerGCWZonePercent> currentServerGCWTotalPercentList = new SWGList<CurrentServerGCWZonePercent>(messageBuilder, 6, 3);
private SWGList<CurrentServerGCWZoneHistory> currentServerGCWZoneHistoryList = new SWGList<CurrentServerGCWZoneHistory>(messageBuilder, 6, 4);
private SWGList<CurrentServerGCWZoneHistory> currentServerGCWTotalHistoryList = new SWGList<CurrentServerGCWZoneHistory>(messageBuilder, 6, 5);
private SWGList<OtherServerGCWZonePercent> otherServerGCWZonePercentList = new SWGList<OtherServerGCWZonePercent>(messageBuilder, 6, 6);
private SWGList<OtherServerGCWZonePercent> otherServerGCWTotalPercentList = new SWGList<OtherServerGCWZonePercent>(messageBuilder, 6, 7);
private int unknown3 = 5;
private List<CurrentServerGCWZoneInfo> currentServerGCWTotalInfoList = new ArrayList<CurrentServerGCWZoneInfo>();
@NotPersistent
private int currentServerGCWTotalInfoListUpdateCounter = 0;
private List<OtherServerGCWZonePercent> otherServerGCWZonePercentList = new ArrayList<OtherServerGCWZonePercent>();
@NotPersistent
private int otherServerGCWZonePercentListUpdateCounter = 0;
private List<OtherServerGCWZonePercent> otherServerGCWTotalPercentList = new ArrayList<OtherServerGCWZonePercent>();
@NotPersistent
private int otherServerGCWTotalPercentListUpdateCounter = 0;
@NotPersistent
private GuildMessageBuilder messageBuilder;
public GuildObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) {
public GuildObject(NGECore core, long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) {
super(objectID, planet, position, orientation, Template);
messageBuilder = new GuildMessageBuilder(this);
this.core = core;
}
public float getComplexity() {
@@ -98,6 +82,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.complexity = complexity;
}
notifyAll(messageBuilder.buildComplexity(complexity));
}
public String getSTFFile() {
@@ -110,6 +96,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.STFFile = STFFile;
}
notifyAll(messageBuilder.buildSTF(STFFile, STFSpacer, STFName));
}
public int getSTFSpacer() {
@@ -122,6 +110,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.STFSpacer = STFSpacer;
}
notifyAll(messageBuilder.buildSTF(STFFile, STFSpacer, STFName));
}
public String getSTFName() {
@@ -134,6 +124,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.STFName = STFName;
}
notifyAll(messageBuilder.buildSTF(STFFile, STFSpacer, STFName));
}
public String getCustomName() {
@@ -146,6 +138,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.customName = customName;
}
notifyAll(messageBuilder.buildCustomName(customName));
}
public int getVolume() {
@@ -158,24 +152,14 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.volume = volume;
}
notifyAll(messageBuilder.buildVolume(volume));
}
public List<Guild> getGuildList() {
public SWGList<Guild> getGuildList() {
return guildList;
}
public int getGuildListUpdateCounter() {
synchronized(objectMutex) {
return guildListUpdateCounter;
}
}
public void setGuildListUpdateCounter(int guildListUpdateCounter) {
synchronized(objectMutex) {
this.guildListUpdateCounter = guildListUpdateCounter;
}
}
public int getServerId() {
synchronized(objectMutex) {
return serverId;
@@ -186,6 +170,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.serverId = serverId;
}
notifyAll(messageBuilder.buildServerId(serverId));
}
public int getUnknown1() {
@@ -198,6 +184,8 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.unknown1 = unknown1;
}
notifyAll(messageBuilder.buildUnknowns(unknown1, unknown2));
}
public short getUnknown2() {
@@ -210,101 +198,53 @@ public class GuildObject extends SWGObject {
synchronized(objectMutex) {
this.unknown2 = unknown2;
}
notifyAll(messageBuilder.buildUnknowns(unknown1, unknown2));
}
public List<CurrentServerGCWZonePercent> getCurrentServerGCWZonePercentList() {
public SWGList<CurrentServerGCWZonePercent> getCurrentServerGCWZonePercentList() {
return currentServerGCWZonePercentList;
}
public int getCurrentServerGCWZonePercentListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWZonePercentListUpdateCounter;
}
}
public void setCurrentServerGCWZonePercentListUpdateCounter(int currentServerGCWZonePercentListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWZonePercentListUpdateCounter = currentServerGCWZonePercentListUpdateCounter;
}
}
public List<CurrentServerGCWZonePercent> getCurrentServerGCWTotalPercentList() {
public SWGList<CurrentServerGCWZonePercent> getCurrentServerGCWTotalPercentList() {
return currentServerGCWTotalPercentList;
}
public int getCurrentServerGCWTotalPercentListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWTotalPercentListUpdateCounter;
}
public SWGList<CurrentServerGCWZoneHistory> getCurrentServerGCWZoneHistoryList() {
return currentServerGCWZoneHistoryList;
}
public void setCurrentServerGCWTotalPercentListUpdateCounter(int currentServerGCWTotalPercentListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWTotalPercentListUpdateCounter = currentServerGCWTotalPercentListUpdateCounter;
}
public SWGList<CurrentServerGCWZoneHistory> getCurrentServerGCWTotalHistoryList() {
return currentServerGCWTotalHistoryList;
}
public List<CurrentServerGCWZoneInfo> getCurrentServerGCWZoneInfoList() {
return currentServerGCWZoneInfoList;
}
public int getCurrentServerGCWZoneInfoListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWZoneInfoListUpdateCounter;
}
}
public void setCurrentServerGCWZoneInfoListUpdateCounter(int currentServerGCWZoneInfoListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWZoneInfoListUpdateCounter = currentServerGCWZoneInfoListUpdateCounter;
}
}
public List<CurrentServerGCWZoneInfo> getCurrentServerGCWTotalInfoList() {
return currentServerGCWTotalInfoList;
}
public int getCurrentServerGCWTotalInfoListUpdateCounter() {
synchronized(objectMutex) {
return currentServerGCWTotalInfoListUpdateCounter;
}
}
public void setCurrentServerGCWTotalInfoListUpdateCounter(int currentServerGCWTotalInfoListUpdateCounter) {
synchronized(objectMutex) {
this.currentServerGCWTotalInfoListUpdateCounter = currentServerGCWTotalInfoListUpdateCounter;
}
}
public List<OtherServerGCWZonePercent> getOtherServerGCWZonePercentList() {
public SWGList<OtherServerGCWZonePercent> getOtherServerGCWZonePercentList() {
return otherServerGCWZonePercentList;
}
public int getOtherServerGCWZonePercentListUpdateCounter() {
synchronized(objectMutex) {
return otherServerGCWZonePercentListUpdateCounter;
}
}
public void setOtherServerGCWZonePercentListUpdateCounter(int otherServerGCWZonePercentListUpdateCounter) {
synchronized(objectMutex) {
this.otherServerGCWZonePercentListUpdateCounter = otherServerGCWZonePercentListUpdateCounter;
}
}
public List<OtherServerGCWZonePercent> getOtherServerGCWTotalPercentList() {
public SWGList<OtherServerGCWZonePercent> getOtherServerGCWTotalPercentList() {
return otherServerGCWTotalPercentList;
}
public int getOtherServerGCWTotalPercentListUpdateCounter() {
public int getUnknown3() {
synchronized(objectMutex) {
return otherServerGCWTotalPercentListUpdateCounter;
return unknown3;
}
}
public void setOtherServerGCWTotalPercentListUpdateCounter(int otherServerGCWTotalPercentListUpdateCounter) {
public void setUnknown3(int unknown3) {
synchronized(objectMutex) {
this.otherServerGCWTotalPercentListUpdateCounter = otherServerGCWTotalPercentListUpdateCounter;
this.unknown3 = unknown3;
}
notifyAll(messageBuilder.buildUnknown3(unknown3));
}
public void sendGCWUpdate() {
IoBuffer buffer = messageBuilder.buildGCWDelta();
if (buffer != null) {
notifyAll(buffer);
}
}
@@ -313,6 +253,20 @@ public class GuildObject extends SWGObject {
destination.getSession().write(messageBuilder.buildBaseline3());
destination.getSession().write(messageBuilder.buildBaseline6());
}
private void notifyAll(IoBuffer buffer) {
//for (int i = 0; i < core.getActiveConnectionsMap().size(); i++) {
// core.getActiveConnectionsMap().get(i).getSession().write(buffer);
//}
System.out.println("Notifying all...");
synchronized(core.getActiveConnectionsMap()) {
for (Client client : core.getActiveConnectionsMap().values()) {
System.out.println("Notifying..." + client.getParent().getCustomName());
client.getSession().write(buffer);
System.out.println("Notified them.");
System.out.println("Packet: " + buffer.getHexDump());
}
}
}
}
@@ -365,6 +365,16 @@ public class PlayerMessageBuilder extends ObjectMessageBuilder {
}
public IoBuffer buildTitleDelta(String title) {
IoBuffer buffer = bufferPool.allocate(4 + getAsciiString(title).length, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(getAsciiString(title));
int size = buffer.position();
buffer.flip();
buffer = createDelta("PLAY", (byte) 3, (short) 1, (short) 0x07, buffer, size + 4);
return buffer;
}
public int getProfData(String profession) {
switch (profession) {
@@ -391,7 +401,11 @@ public class PlayerMessageBuilder extends ObjectMessageBuilder {
}
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
// TODO Auto-generated method stub
}
@Override
public void sendBaselines() {
@@ -134,6 +134,8 @@ public class PlayerObject extends SWGObject {
synchronized(objectMutex) {
this.title = title;
}
notifyObservers(messageBuilder.buildTitleDelta(title), true);
}
public String getProfession() {
@@ -122,12 +122,17 @@ public class TangibleMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
// TODO Auto-generated method stub
}
@Override
public void sendBaselines() {
// TODO Auto-generated method stub
}
}
@@ -132,13 +132,17 @@ public class WeaponMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
// TODO Auto-generated method stub
}
@Override
public void sendBaselines() {
// TODO Auto-generated method stub
}
}
+6
View File
@@ -136,6 +136,12 @@ public class LoginService implements INetworkDispatch{
StationIdHasJediSlot jediSlot = new StationIdHasJediSlot(false);
ServerNowEpochTime time = new ServerNowEpochTime((int) (System.currentTimeMillis() / 1000));
if (client.getSession().containsAttribute("tradeSession") == true) {
System.out.println("Has attribute: " + session.getAttribute("tradeSession").toString());
client.getSession().removeAttribute("tradeSession");
System.out.println("Removed tradeSession Attribute @ LoginService.java");
}
session.write(time.serialize());
session.write(clientToken.serialize());
session.write(servers.serialize());
+3
View File
@@ -120,6 +120,9 @@ public class SimulationService implements INetworkDispatch {
core.commandService.registerCommand("giveitem");
core.commandService.registerCommand("object");
core.commandService.registerCommand("getattributesbatch");
core.commandService.registerCommand("pvp");
core.commandService.registerCommand("setcurrentskilltitle");
core.commandService.registerCommand("tip");
}
+121 -99
View File
@@ -21,6 +21,7 @@
******************************************************************************/
package services.gcw;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -28,7 +29,17 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import resources.objects.CurrentServerGCWZoneInfo;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import protocol.swg.GcwGroupsRsp;
import protocol.swg.GcwRegionsReq;
import protocol.swg.GcwRegionsRsp;
import protocol.swg.GetMapLocationsMessage;
import protocol.swg.GetMapLocationsResponseMessage;
import resources.common.Opcodes;
import resources.objects.CurrentServerGCWZoneHistory;
import resources.objects.CurrentServerGCWZonePercent;
import resources.objects.OtherServerGCWZonePercent;
import resources.objects.guild.GuildObject;
@@ -36,112 +47,36 @@ import resources.objects.guild.GuildObject;
import main.NGECore;
import engine.clients.Client;
import engine.resources.objects.SWGObject;
import engine.resources.service.INetworkDispatch;
import engine.resources.service.INetworkRemoteEvent;
@SuppressWarnings("unused")
public class GCWService implements INetworkDispatch {
private NGECore core;
private GuildObject object;
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private List<String> zoneList = Arrays.asList(new String[] { "corellia_airspace", "corellia_pve", "corellia_pvp", "dantooine_airspace", "dantooine_pve", "dantooine_pvp", "dathomir_airspace", "dathomir_pve", "dathomir_pvp", "endor_airspace", "endor_pve", "endor_pvp", "endor_pvp_battlefield", "gcw_region_corellia_1", "gcw_region_corellia_10", "gcw_region_corellia_11", "gcw_region_corellia_12", "gcw_region_corellia_13", "gcw_region_corellia_14", "gcw_region_corellia_2", "gcw_region_corellia_3", "gcw_region_corellia_4", "gcw_region_corellia_5", "gcw_region_corellia_6", "gcw_region_corellia_7", "gcw_region_corellia_8", "gcw_region_corellia_9", "gcw_region_dantooine_1", "gcw_region_dantooine_10", "gcw_region_dantooine_11", "gcw_region_dantooine_12", "gcw_region_dantooine_13", "gcw_region_dantooine_14", "gcw_region_dantooine_15", "gcw_region_dantooine_16", "gcw_region_dantooine_17", "gcw_region_dantooine_2", "gcw_region_dantooine_3", "gcw_region_dantooine_4", "gcw_region_dantooine_5", "gcw_region_dantooine_6", "gcw_region_dantooine_7", "gcw_region_dantooine_8", "gcw_region_dantooine_9", "gcw_region_dathomir_1", "gcw_region_dathomir_10", "gcw_region_dathomir_11", "gcw_region_dathomir_12", "gcw_region_dathomir_13", "gcw_region_dathomir_2", "gcw_region_dathomir_3", "gcw_region_dathomir_4", "gcw_region_dathomir_5", "gcw_region_dathomir_6", "gcw_region_dathomir_7", "gcw_region_dathomir_8", "gcw_region_dathomir_9", "gcw_region_endor_1", "gcw_region_endor_10", "gcw_region_endor_11", "gcw_region_endor_12", "gcw_region_endor_13", "gcw_region_endor_14", "gcw_region_endor_15", "gcw_region_endor_16", "gcw_region_endor_2", "gcw_region_endor_3", "gcw_region_endor_4", "gcw_region_endor_5", "gcw_region_endor_6", "gcw_region_endor_7", "gcw_region_endor_8", "gcw_region_endor_9", "gcw_region_lok_1", "gcw_region_lok_10", "gcw_region_lok_11", "gcw_region_lok_12", "gcw_region_lok_13", "gcw_region_lok_14", "gcw_region_lok_2", "gcw_region_lok_3", "gcw_region_lok_4", "gcw_region_lok_5", "gcw_region_lok_6", "gcw_region_lok_7", "gcw_region_lok_8", "gcw_region_lok_9", "gcw_region_naboo_1", "gcw_region_naboo_10", "gcw_region_naboo_11", "gcw_region_naboo_12", "gcw_region_naboo_13", "gcw_region_naboo_14", "gcw_region_naboo_2", "gcw_region_naboo_3", "gcw_region_naboo_4", "gcw_region_naboo_5", "gcw_region_naboo_6", "gcw_region_naboo_7", "gcw_region_naboo_8", "gcw_region_naboo_9", "gcw_region_rori_1", "gcw_region_rori_10", "gcw_region_rori_11", "gcw_region_rori_12", "gcw_region_rori_13", "gcw_region_rori_2", "gcw_region_rori_3", "gcw_region_rori_4", "gcw_region_rori_5", "gcw_region_rori_6", "gcw_region_rori_7", "gcw_region_rori_8", "gcw_region_rori_9", "gcw_region_talus_1", "gcw_region_talus_10", "gcw_region_talus_11", "gcw_region_talus_12", "gcw_region_talus_13", "gcw_region_talus_14", "gcw_region_talus_15", "gcw_region_talus_16", "gcw_region_talus_2", "gcw_region_talus_3", "gcw_region_talus_4", "gcw_region_talus_5", "gcw_region_talus_6", "gcw_region_talus_7", "gcw_region_talus_8", "gcw_region_talus_9", "gcw_region_tatooine_1", "gcw_region_tatooine_10", "gcw_region_tatooine_11", "gcw_region_tatooine_12", "gcw_region_tatooine_13", "gcw_region_tatooine_2", "gcw_region_tatooine_3", "gcw_region_tatooine_4", "gcw_region_tatooine_5", "gcw_region_tatooine_6", "gcw_region_tatooine_7", "gcw_region_tatooine_8", "gcw_region_tatooine_9", "gcw_region_yavin4_1", "gcw_region_yavin4_10", "gcw_region_yavin4_11", "gcw_region_yavin4_12", "gcw_region_yavin4_13", "gcw_region_yavin4_14", "gcw_region_yavin4_15", "gcw_region_yavin4_16", "gcw_region_yavin4_17", "gcw_region_yavin4_18", "gcw_region_yavin4_2", "gcw_region_yavin4_3", "gcw_region_yavin4_4", "gcw_region_yavin4_5", "gcw_region_yavin4_6", "gcw_region_yavin4_7", "gcw_region_yavin4_8", "gcw_region_yavin4_9", "lok_airspace", "lok_pve", "lok_pvp", "naboo_airspace", "naboo_pve", "naboo_pvp", "rori_airspace", "rori_pve", "rori_pvp", "space_corellia_space_pve", "space_corellia_space_pvp", "space_dantooine_space_pve", "space_dantooine_space_pvp", "space_dathomir_space_pve", "space_dathomir_space_pvp", "space_endor_space_pve", "space_endor_space_pvp", "space_lok_space_pve", "space_lok_space_pvp", "space_naboo_space_pve", "space_naboo_space_pvp", "space_tatooine_space_pve", "space_tatooine_space_pvp", "space_yavin4_space_pve", "space_yavin4_space_pvp", "talus_airspace", "talus_pve", "talus_pvp", "tatooine_airspace", "tatooine_pve", "tatooine_pvp", "yavin4_airspace", "yavin4_pve", "yavin4_pvp", "yavin4_pvp_battlefield" });
private List<String> totalList = Arrays.asList(new String[] { "corellia", "dantooine", "dathomir", "endor", "galaxy", "lok", "naboo", "rori", "talus", "tatooine", "yavin4" });
public GCWService(final NGECore core) {
this.core = core;
// The GCW object is also the guild object; someone at SOE got lazy
object = this.core.guildService.getGuildObject();
// Load GCW Zones
// TODO load from the stf file in future
String[] zones =
{
"corellia_airspace", "corellia_pve", "corellia_pvp", "dantooine_airspace",
"dantooine_pve", "dantooine_pvp", "dathomir_airspace", "dathomir_pve", "dathomir_pvp",
"endor_airspace", "endor_pve", "endor_pvp", "endor_pvp_battlefield",
"gcw_region_corellia_1", "gcw_region_corellia_10", "gcw_region_corellia_11",
"gcw_region_corellia_12", "gcw_region_corellia_13", "gcw_region_corellia_14",
"gcw_region_corellia_2", "gcw_region_corellia_3", "gcw_region_corellia_4",
"gcw_region_corellia_5", "gcw_region_corellia_6", "gcw_region_corellia_7",
"gcw_region_corellia_8", "gcw_region_corellia_9", "gcw_region_dantooine_1",
"gcw_region_dantooine_10", "gcw_region_dantooine_11", "gcw_region_dantooine_12",
"gcw_region_dantooine_13", "gcw_region_dantooine_14", "gcw_region_dantooine_15",
"gcw_region_dantooine_16", "gcw_region_dantooine_17", "gcw_region_dantooine_2",
"gcw_region_dantooine_3", "gcw_region_dantooine_4", "gcw_region_dantooine_5",
"gcw_region_dantooine_6", "gcw_region_dantooine_7", "gcw_region_dantooine_8",
"gcw_region_dantooine_9", "gcw_region_dathomir_1", "gcw_region_dathomir_10",
"gcw_region_dathomir_11", "gcw_region_dathomir_12", "gcw_region_dathomir_13",
"gcw_region_dathomir_2", "gcw_region_dathomir_3", "gcw_region_dathomir_4",
"gcw_region_dathomir_5", "gcw_region_dathomir_6", "gcw_region_dathomir_7",
"gcw_region_dathomir_8", "gcw_region_dathomir_9", "gcw_region_endor_1",
"gcw_region_endor_10", "gcw_region_endor_11", "gcw_region_endor_12",
"gcw_region_endor_13", "gcw_region_endor_14", "gcw_region_endor_15",
"gcw_region_endor_16", "gcw_region_endor_2", "gcw_region_endor_3",
"gcw_region_endor_4", "gcw_region_endor_5", "gcw_region_endor_6",
"gcw_region_endor_7", "gcw_region_endor_8", "gcw_region_endor_9", "gcw_region_lok_1",
"gcw_region_lok_10", "gcw_region_lok_11", "gcw_region_lok_12", "gcw_region_lok_13",
"gcw_region_lok_14", "gcw_region_lok_2", "gcw_region_lok_3", "gcw_region_lok_4",
"gcw_region_lok_5", "gcw_region_lok_6", "gcw_region_lok_7", "gcw_region_lok_8",
"gcw_region_lok_9", "gcw_region_naboo_1", "gcw_region_naboo_10",
"gcw_region_naboo_11", "gcw_region_naboo_12", "gcw_region_naboo_13",
"gcw_region_naboo_14", "gcw_region_naboo_2", "gcw_region_naboo_3",
"gcw_region_naboo_4", "gcw_region_naboo_5", "gcw_region_naboo_6", "gcw_region_naboo_7",
"gcw_region_naboo_8", "gcw_region_naboo_9", "gcw_region_rori_1", "gcw_region_rori_10",
"gcw_region_rori_11", "gcw_region_rori_12", "gcw_region_rori_13", "gcw_region_rori_2",
"gcw_region_rori_3", "gcw_region_rori_4", "gcw_region_rori_5", "gcw_region_rori_6",
"gcw_region_rori_7", "gcw_region_rori_8", "gcw_region_rori_9", "gcw_region_talus_1",
"gcw_region_talus_10", "gcw_region_talus_11", "gcw_region_talus_12", "gcw_region_talus_13",
"gcw_region_talus_14", "gcw_region_talus_15", "gcw_region_talus_16", "gcw_region_talus_2",
"gcw_region_talus_3", "gcw_region_talus_4", "gcw_region_talus_5", "gcw_region_talus_6",
"gcw_region_talus_7", "gcw_region_talus_8", "gcw_region_talus_9", "gcw_region_tatooine_1",
"gcw_region_tatooine_10", "gcw_region_tatooine_11", "gcw_region_tatooine_12",
"gcw_region_tatooine_13", "gcw_region_tatooine_2", "gcw_region_tatooine_3",
"gcw_region_tatooine_4", "gcw_region_tatooine_5", "gcw_region_tatooine_6",
"gcw_region_tatooine_7", "gcw_region_tatooine_8", "gcw_region_tatooine_9",
"gcw_region_yavin4_1", "gcw_region_yavin4_10", "gcw_region_yavin4_11",
"gcw_region_yavin4_12", "gcw_region_yavin4_13", "gcw_region_yavin4_14",
"gcw_region_yavin4_15", "gcw_region_yavin4_16", "gcw_region_yavin4_17",
"gcw_region_yavin4_18", "gcw_region_yavin4_2", "gcw_region_yavin4_3",
"gcw_region_yavin4_4", "gcw_region_yavin4_5", "gcw_region_yavin4_6",
"gcw_region_yavin4_7", "gcw_region_yavin4_8", "gcw_region_yavin4_9", "lok_airspace",
"lok_pve", "lok_pvp", "naboo_airspace", "naboo_pve", "naboo_pvp", "rori_airspace",
"rori_pve", "rori_pvp", "space_corellia_space_pve", "space_corellia_space_pvp",
"space_dantooine_space_pve", "space_dantooine_space_pvp", "space_dathomir_space_pve",
"space_dathomir_space_pvp", "space_endor_space_pve", "space_endor_space_pvp",
"space_lok_space_pve", "space_lok_space_pvp", "space_naboo_space_pve",
"space_naboo_space_pvp", "space_tatooine_space_pve", "space_tatooine_space_pvp",
"space_yavin4_space_pve", "space_yavin4_space_pvp", "talus_airspace", "talus_pve",
"talus_pvp", "tatooine_airspace", "tatooine_pve", "tatooine_pvp", "yavin4_airspace",
"yavin4_pve", "yavin4_pvp", "yavin4_pvp_battlefield"
};
List<String> zoneList = Arrays.asList(zones);
this.object = this.core.guildService.getGuildObject();
for (int i = 0; i < zoneList.size(); i++) {
object.getCurrentServerGCWZonePercentList().add(new CurrentServerGCWZonePercent(zoneList.get(i)));
object.getCurrentServerGCWZoneInfoList().add(new CurrentServerGCWZoneInfo(zoneList.get(i)));
object.getCurrentServerGCWZoneHistoryList().add(new CurrentServerGCWZoneHistory(zoneList.get(i)));
object.getOtherServerGCWZonePercentList().add(new OtherServerGCWZonePercent(zoneList.get(i)));
object.setCurrentServerGCWZonePercentListUpdateCounter(object.getCurrentServerGCWZonePercentListUpdateCounter() + 1);
object.setCurrentServerGCWZoneInfoListUpdateCounter(object.getCurrentServerGCWZoneInfoListUpdateCounter() + 1);
object.setOtherServerGCWZonePercentListUpdateCounter(object.getOtherServerGCWZonePercentListUpdateCounter() + 1);
}
// Load GCW Totals
// TODO load from the stf file in future
String[] totals =
{
"corellia", "dantooine", "dathomir", "endor", "galaxy",
"lok", "naboo", "rori", "talus", "tatooine", "yavin4"
};
List<String> totalList = Arrays.asList(totals);
for (int i = 0; i < totalList.size(); i++) {
object.getCurrentServerGCWTotalPercentList().add(new CurrentServerGCWZonePercent(totalList.get(i)));
object.getCurrentServerGCWTotalInfoList().add(new CurrentServerGCWZoneInfo(totalList.get(i)));
object.getCurrentServerGCWTotalHistoryList().add(new CurrentServerGCWZoneHistory(totalList.get(i)));
object.getOtherServerGCWTotalPercentList().add(new OtherServerGCWZonePercent(totalList.get(i)));
object.setCurrentServerGCWTotalPercentListUpdateCounter(object.getCurrentServerGCWTotalPercentListUpdateCounter() + 1);
object.setCurrentServerGCWTotalInfoListUpdateCounter(object.getCurrentServerGCWTotalInfoListUpdateCounter() + 1);
object.setOtherServerGCWTotalPercentListUpdateCounter(object.getOtherServerGCWTotalPercentListUpdateCounter() + 1);
}
// Update the GCW Zones every minute as in live
@@ -149,26 +84,113 @@ public class GCWService implements INetworkDispatch {
@Override
public void run() {
synchronized(core.getActiveConnectionsMap()) {
for (Client c : core.getActiveConnectionsMap().values()) {
if (c.getParent() != null) {
//
}
}
}
//object.sendGCWUpdate();
//addGCWPointsToZonesWithFactionalPresence(new Client());
//removeGCWPointFromZonesWithNoFactionalPresence(new Client());
}
}, 1, 1, TimeUnit.MINUTES);
// Update other server GCW Zones every 15 minutes (roughly like live I think)
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
/*
for (int i = 0; i < object.getOtherServerGCWZonePercentList().size(); i++) {
object.getOtherServerGCWZonePercentList().get(i).setPercent(object.getCurrentServerGCWZonePercentList().get(i).getPercent());
object.getOtherServerGCWZonePercentList().set(i, object.getOtherServerGCWZonePercentList().get(i));
}
for (int i = 0; i < object.getOtherServerGCWTotalPercentList().size(); i++) {
object.getOtherServerGCWTotalPercentList().get(i).setPercent(object.getCurrentServerGCWTotalPercentList().get(i).getPercent());
object.getOtherServerGCWZonePercentList().set(i, object.getOtherServerGCWZonePercentList().get(i));
}
*/
}
//}, 15, 15, TimeUnit.MINUTES);
}, 2, 5, TimeUnit.MINUTES);
// Reset weak GCW Zones every 2 days as in live
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
/*
resetWeakGCWZones();
*/
}
//}, 2, 2, TimeUnit.DAYS);
}, 2, 5, TimeUnit.MINUTES);
}
private void addGCWPointsToZonesWithFactionalPresence(Client client) {
}
private void removeGCWPointFromZonesWithNoFactionalPresence(Client client) {
}
private void resetWeakGCWZones() {
for (int i = 0; i < object.getCurrentServerGCWZonePercentList().size(); i++) {
CurrentServerGCWZonePercent zone = object.getCurrentServerGCWZonePercentList().get(i);
if (zone.getGCWPoints() == 0 && zone.getPercent() != 50) {
zone.setPercent(50, object.getCurrentServerGCWZoneHistoryList());
object.getCurrentServerGCWZonePercentList().set(i, zone);
}
}
for (int i = 0; i < object.getCurrentServerGCWTotalPercentList().size(); i++) {
CurrentServerGCWZonePercent zone = object.getCurrentServerGCWTotalPercentList().get(i);
if (zone.getGCWPoints() == 0 && zone.getPercent() != 50) {
zone.setPercent(50, object.getCurrentServerGCWTotalHistoryList());
object.getCurrentServerGCWTotalPercentList().set(i, zone);
}
}
}
@Override
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> arg0, Map<Integer, INetworkRemoteEvent> arg1) {
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> swgOpcodes, Map<Integer, INetworkRemoteEvent> objControllerOpcodes) {
swgOpcodes.put(Opcodes.GcwRegionsReq, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
data.position(0);
GcwRegionsReq gcwRegionsReq = new GcwRegionsReq();
gcwRegionsReq.deserialize(data);
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
if (client == null || client.getSession() == null) {
return;
}
SWGObject object = client.getParent();
if (object == null) {
return;
}
session.write((new GcwRegionsRsp()).serialize());
session.write((new GcwGroupsRsp()).serialize());
}
});
}
@Override
public void shutdown() {
}
}
+5 -8
View File
@@ -21,7 +21,6 @@
******************************************************************************/
package services.guild;
import java.util.List;
import java.util.Map;
import org.apache.mina.core.buffer.IoBuffer;
@@ -29,11 +28,13 @@ import org.apache.mina.core.session.IoSession;
import resources.common.Opcodes;
import resources.objects.Guild;
import resources.objects.SWGList;
import resources.objects.guild.GuildObject;
import main.NGECore;
import engine.clients.Client;
import engine.resources.objects.SWGObject;
import engine.resources.service.INetworkDispatch;
import engine.resources.service.INetworkRemoteEvent;
@@ -48,24 +49,20 @@ public class GuildService implements INetworkDispatch {
object = (GuildObject) this.core.objectService.createObject("object/guild/shared_guild_object.iff", core.terrainService.getPlanetList().get(0));
}
public Guild createGuild(String abbreviation, String name) {
public Guild createGuild(String abbreviation, String name, SWGObject leader) {
int id = ((object.getGuildList().get(object.getGuildList().size()).getId()) + 1);
Guild guild = new Guild(id, abbreviation, name);
Guild guild = new Guild(id, abbreviation, name, leader);
object.getGuildList().add(guild);
return guild;
}
public void addGuild(Guild guild) {
object.getGuildList().add(guild);
}
public GuildObject getGuildObject() {
return object;
}
public List<Guild> getGuildList() {
public SWGList<Guild> getGuildList() {
return object.getGuildList();
}
+1 -1
View File
@@ -155,7 +155,7 @@ public class ObjectService implements INetworkDispatch {
} else if(Template.startsWith("object/guild")) {
object = new GuildObject(objectID, planet, position, orientation, Template);
object = new GuildObject(core, objectID, planet, position, orientation, Template);
} else {
+25 -2
View File
@@ -79,12 +79,12 @@ public class SUIService implements INetworkDispatch {
if(target == null || owner == null)
return;
core.scriptService.callScript("scripts/radial/", getRadialFilename(target), "createRadial", core, owner, target, request.getRadialOptions());
if(getRadialFilename(target).equals("default"))
return;
sendRadial(owner, target, request.getRadialOptions(), request.getRadialCount());
}
@@ -290,7 +290,30 @@ public class SUIService implements INetworkDispatch {
return window;
}
public SUIWindow createInputBox(int type, String title, String promptText, SWGObject owner, SWGObject rangeObject, float maxDistance) {
SUIWindow window = createSUIWindow("Script.inputBox", owner, rangeObject, maxDistance);
window.setProperty("bg.caption.lblTitle:Text", title);
window.setProperty("Prompt.lblPrompt:Text", promptText);
switch(type) {
case InputBoxType.INPUT_BOX_OK:
window.setProperty("btnOk:visible", "True");
window.setProperty("btnOk:Text", "@ok");
window.setProperty("btnCancel:visible", "False");
window.setProperty("cmbInput:visible", "False");
break;
case InputBoxType.INPUT_BOX_OK_CANCEL:
window.setProperty("btnOk:visible", "True");
window.setProperty("btnCancel:visible", "True");
window.setProperty("btnCancel:Text", "@cancel");
window.setProperty("btnOk:Text", "@ok");
window.setProperty("cmbInput:visible", "False");
}
return window;
}
public void closeSUIWindow(SWGObject owner, int id) {
if(owner.getClient() == null || owner.getClient().getSession() == null)
+461
View File
@@ -0,0 +1,461 @@
package services.trade;
import java.nio.ByteOrder;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import main.NGECore;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import protocol.swg.clientSecureTradeManager.AbortTradeMessage;
import protocol.swg.clientSecureTradeManager.AcceptTransactionMessage;
import protocol.swg.clientSecureTradeManager.AddItemMessage;
import protocol.swg.clientSecureTradeManager.BeginTradeMessage;
import protocol.swg.clientSecureTradeManager.GiveMoneyMessage;
import protocol.swg.clientSecureTradeManager.RemoveItemMessage;
import protocol.swg.clientSecureTradeManager.TradeCompleteMessage;
import protocol.swg.clientSecureTradeManager.TradeOpcodes;
import protocol.swg.clientSecureTradeManager.UnAcceptTransactionMessage;
import protocol.swg.objectControllerObjects.SecureTrade;
import resources.common.ObjControllerOpcodes;
import resources.objects.creature.CreatureObject;
import engine.clients.Client;
import engine.resources.objects.SWGObject;
import engine.resources.service.INetworkDispatch;
import engine.resources.service.INetworkRemoteEvent;
@SuppressWarnings("unused")
public class TradeService implements INetworkDispatch{
private NGECore core;
private long recieverID;
private long senderID;
private Hashtable<SWGObject, Long> tradingObjectsTable = new Hashtable<SWGObject, Long>();
// key = objectToGive, value = giver's ID
// need to be sure that no giver ID exists in table before adding value
private Hashtable<Long, Integer> tradingCreditsTable = new Hashtable<Long, Integer>();
// key = ID of giver value = amnt recieving
public TradeService(NGECore core) {
this.core = core;
}
@Override
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> swgOpcodes, Map<Integer, INetworkRemoteEvent> objControllerOpcodes) {
objControllerOpcodes.put(ObjControllerOpcodes.SECURE_TRADE, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
SecureTrade request = new SecureTrade();
request.deserialize(data);
senderID = request.getSenderID();
recieverID = request.getRecieverID();
CreatureObject recieverObject = (CreatureObject) core.objectService.getObject(recieverID);
CreatureObject senderObject = (CreatureObject) core.objectService.getObject(senderID);
Client senderClient = senderObject.getClient();
Client recieverClient = recieverObject.getClient();
int senderClientId = senderClient.getConnectionId();
int recieverClientId = recieverClient.getConnectionId();
//System.out.println("Sender isConnected: " + senderObject.getClient().getSession().isConnected());
//System.out.println("Reciever isConnected: " + recieverObject.getClient().getSession().isConnected());
if (recieverClient.getSession().containsAttribute("tradeSession") == true) {
if(senderClient.getSession().containsAttribute("tradeSession") == false) {
{
senderClient.getSession().setAttribute("tradeSession", recieverID);
}
BeginTradeMessage senderResponse = new BeginTradeMessage(recieverID);
senderClient.getSession().write(senderResponse.serialize());
BeginTradeMessage recieverResponse = new BeginTradeMessage(senderID);
recieverClient.getSession().write(recieverResponse.serialize());
}
}
else {
// creates a new trade session for the user who sent the request. It's given the objectID
// that the player wants to trade with.
senderClient.getSession().setAttribute("tradeSession", recieverID);
recieverObject.sendSystemMessage(senderObject.getCustomName() + " wants to trade with you.", (byte) 0);
}
}
});
swgOpcodes.put(TradeOpcodes.AbortTradeMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
data.position(0);
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
if (client == null)
return;
if (client.getSession().getAttribute("tradeSession") == null)
{
TradeCompleteMessage completeTrade = new TradeCompleteMessage();
AbortTradeMessage nullResponse = new AbortTradeMessage();
client.getSession().write(completeTrade.serialize());
client.getSession().write(nullResponse.serialize());
}
long tradingWithClient = (long) client.getSession().getAttribute("tradeSession");
CreatureObject tradee = (CreatureObject) core.objectService.getObject(tradingWithClient);
Client tradeeClient = tradee.getClient();
if(client.getSession() == null)
return;
SWGObject object = client.getParent();
SWGObject tradeeObject = tradeeClient.getParent();
if(object == null)
return;
SWGObject tradeObject = null;
Iterator<Map.Entry<SWGObject, Long>> itr = tradingObjectsTable.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<SWGObject, Long> entry = itr.next();
if(tradingWithClient == entry.getValue()) {
tradeObject = entry.getKey();
itr.remove();
}
}
client.getSession().removeAttribute("tradeSession");
tradeeClient.getSession().removeAttribute("tradeSession");
// make sure that tradeSession got removed.
if (tradeeClient.getSession().containsAttribute("tradeSession") && client.getSession().containsAttribute("tradeSession"))
return;
TradeCompleteMessage completeTrade = new TradeCompleteMessage();
AbortTradeMessage response = new AbortTradeMessage();
tradeeClient.getSession().write(response.serialize());
client.getSession().write(response.serialize());
client.getSession().write(completeTrade.serialize());
tradeeClient.getSession().write(completeTrade.serialize());
}
});
swgOpcodes.put(TradeOpcodes.AddItemMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
data.position(0);
AddItemMessage addItem = new AddItemMessage();
addItem.deserialize(data);
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
if (client == null)
return;
long tradeItemID = addItem.getTradeObjectID();
long tradingWithClient = (long) client.getSession().getAttribute("tradeSession");
CreatureObject tradee = (CreatureObject) core.objectService.getObject(tradingWithClient);
SWGObject objectToTrade = (SWGObject) core.objectService.getObject(tradeItemID);
if (objectToTrade == null) {
System.out.println("objectToTrade is null: " + tradeItemID);
return;
}
else {
addItemForTrade(objectToTrade, tradingWithClient);
System.out.println("Trading item: " + objectToTrade.getCustomName() + " detail: " + objectToTrade.getDetailFilename());
System.out.println("tradingObjectTable: " + tradingObjectsTable.toString());
AddItemMessage tradeeResponse = new AddItemMessage();
tradeeResponse.setTradeObjectID(tradeItemID);
tradee.getClient().getSession().write(tradeeResponse.serialize());
//System.out.println("AddItemMessage in TradeService: " + data.getHexDump());
}
}
});
swgOpcodes.put(TradeOpcodes.GiveMoneyMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
data.position(0);
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
long tradingWithClient = (long) client.getSession().getAttribute("tradeSession");
CreatureObject tradingPartner = (CreatureObject) core.objectService.getObject(tradingWithClient);
CreatureObject sender = (CreatureObject) client.getParent();
GiveMoneyMessage fromClient = new GiveMoneyMessage();
fromClient.deserialize(data);
int givingCredits = fromClient.getTradingCredits();
if (givingCredits <= sender.getCashCredits()) {
addMoneyForTrade(tradingWithClient, givingCredits);
GiveMoneyMessage toTradingPartner = new GiveMoneyMessage();
toTradingPartner.setTradingCredits(givingCredits);
tradingPartner.getClient().getSession().write(toTradingPartner.serialize());
}
}
});
swgOpcodes.put(TradeOpcodes.RemoveItemMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer buffer) throws Exception {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.position(0);
RemoveItemMessage request = new RemoveItemMessage();
long objectToKeepID = request.getObjectID();
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
long tradingWithClient = (long) client.getSession().getAttribute("tradeSession");
CreatureObject tradePartner = (CreatureObject) core.objectService.getObject(tradingWithClient);
RemoveItemMessage response = new RemoveItemMessage();
response.setObjectID(objectToKeepID);
tradePartner.getClient().getSession().write(response.serialize());
removeItemForTrade(core.objectService.getObject(objectToKeepID));
}
});
swgOpcodes.put(TradeOpcodes.AcceptTransactionMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer buffer) throws Exception {
// client sends this packet to the server and then the server sends it to client.
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
long tradingWithClient = (long) client.getSession().getAttribute("tradeSession");
CreatureObject tradePartner = (CreatureObject) core.objectService.getObject(tradingWithClient);
AcceptTransactionMessage acceptedTrade = new AcceptTransactionMessage();
tradePartner.getClient().getSession().write(acceptedTrade.serialize());
}
});
swgOpcodes.put(TradeOpcodes.UnAcceptTransactionMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer buffer) throws Exception {
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
long tradingWithClient = (long) client.getSession().getAttribute("tradeSession");
CreatureObject tradePartner = (CreatureObject) core.objectService.getObject(tradingWithClient);
UnAcceptTransactionMessage undoAccept = new UnAcceptTransactionMessage();
tradePartner.getClient().getSession().write(undoAccept.serialize());
}
});
// not used, but just in case.... VerifyTradeMessage is sent instead when a user
// hits the Accept button. Can use this as an additional check if need to.
swgOpcodes.put(TradeOpcodes.BeginVerificationMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer buffer) throws Exception {
System.out.println("Got BeginVerificationMessage");
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
client.getSession().setAttribute("tradeSessionIsVerified");
System.out.println("Verified client");
}
});
swgOpcodes.put(TradeOpcodes.VerifyTradeMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer buffer) throws Exception {
// Sent first!
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
long tradingWithClient = (long) getTradeAttribute(client);
CreatureObject tradePartner = (CreatureObject) core.objectService.getObject(tradingWithClient);
CreatureObject actingTrader = (CreatureObject) client.getParent();
CreatureObject tradePartnerContainer = (CreatureObject) tradePartner.getContainer();
SWGObject tradePartnerInventory = tradePartner.getSlottedObject("inventory");
SWGObject actingTraderInventory = actingTrader.getSlottedObject("inventory");
SWGObject tradeObject = null;
//if (tradePartner == null || actingTrader == null)
//return;
//BeginVerificationMessage verifyMessage = new BeginVerificationMessage();
//client.getSession().write(verifyMessage.serialize());
//client.getSession().setAttribute("tradeSessionIsVerified");
//tradePartner.getClient().getSession().write(verifyMessage.serialize());
//tradePartner.getClient().getSession().setAttribute("tradeSessionIsVerified");
client.getSession().setAttribute("tradeSessionIsVerified");
if (tradePartner.getClient().getSession().getAttribute("tradeSessionIsVerified") == null)
return;
else if (tradePartner.getClient().getSession().containsAttribute("tradeSessionIsVerified"))
{
Iterator<Map.Entry<SWGObject, Long>> itr = tradingObjectsTable.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<SWGObject, Long> entry = itr.next();
if(tradingWithClient == entry.getValue()) {
tradeObject = entry.getKey();
if (actingTrader == null || tradePartnerContainer == null || tradePartner == null)
{
cleanTradeSession(client, tradePartner.getClient());
}
actingTraderInventory.transferTo(tradePartner, tradePartnerInventory, tradeObject);
itr.remove();
}
}
int moneyToGive = 0;
for(Map.Entry<Long, Integer> entry : tradingCreditsTable.entrySet()) {
if(tradingWithClient == entry.getKey()) {
moneyToGive = entry.getValue();
tradingCreditsTable.remove(tradingWithClient);
}
}
int tradePartnerCredits = tradePartner.getCashCredits();
if (moneyToGive != 0) {
actingTrader.setCashCredits(tradePartnerCredits - moneyToGive);
tradePartner.setCashCredits(tradePartnerCredits + moneyToGive);
}
System.out.println("Finished trading items/credits");
cleanTradeSession(client, tradePartner.getClient());
}
}
});
}
public long getTradeAttribute(Client client) {
long tradeSessionValue;
tradeSessionValue = (long) client.getSession().getAttribute("tradeSession");
return tradeSessionValue;
}
public Hashtable<SWGObject, Long> getTradingObjectMap() {
return tradingObjectsTable;
}
public void addItemForTrade(SWGObject swgObject, long tradePartnerID) {
if (tradingObjectsTable.containsKey(swgObject)) {
removeItemForTrade(swgObject);
}
tradingObjectsTable.put(swgObject, tradePartnerID);
}
public void removeItemForTrade(SWGObject swgObject) {
tradingObjectsTable.remove(swgObject);
}
public void addMoneyForTrade(long tradePartnerID, int creditsAmount) {
if (tradingCreditsTable.containsKey(tradePartnerID))
{
removeMoneyForTrade(tradePartnerID);
}
tradingCreditsTable.put(tradePartnerID, creditsAmount);
}
public void removeMoneyForTrade(long tradePartnerID) {
tradingCreditsTable.remove(tradePartnerID);
}
public void cleanTradeSession(Client actorClient, Client targetTradeClient) {
TradeCompleteMessage partnerCompleteTrade = new TradeCompleteMessage();
targetTradeClient.getSession().write(partnerCompleteTrade.serialize());
TradeCompleteMessage clientCompleteTrade = new TradeCompleteMessage();
actorClient.getSession().write(clientCompleteTrade.serialize());
actorClient.getSession().removeAttribute("tradeSession");
actorClient.getSession().removeAttribute("tradeSessionIsVerified");
targetTradeClient.getSession().removeAttribute("tradeSession");
targetTradeClient.getSession().removeAttribute("tradeSessionIsVerified");
}
@Override
public void shutdown() {
// XXX Auto-generated method stub
}
}