Added radials which are handled by python scripts, updated engine, objects now load serverside template at creation

This commit is contained in:
Light2
2013-07-08 23:38:41 +02:00
parent 3afd5eca3a
commit e457b9711c
18 changed files with 828 additions and 11 deletions
Binary file not shown.
@@ -1,4 +1,6 @@
import sys
def setup(core, object):
return
object.setAttachment('radial_filename', 'bank')
return
+27
View File
@@ -0,0 +1,27 @@
from resources.common import RadialOptions
import sys
def createRadial(core, owner, target, radials):
radials.clear()
bank = owner.getSlottedObject('bank')
if bank:
radials.add(RadialOptions(0, 21, 1, ''))
radials.add(RadialOptions(0, 7, 1, ''))
radials.add(RadialOptions(1, RadialOptions.bankTransfer, 3, '@sui:bank_credits'))
radials.add(RadialOptions(1, RadialOptions.bankitems, 3, '@sui:bank_items'))
if owner.getBankCredits() > 0:
radials.add(RadialOptions(1, RadialOptions.bankWithdrawAll, 3, '@sui:bank_withdrawall'))
if owner.getCashCredits() > 0:
radials.add(RadialOptions(1, RadialOptions.bankDepositAll, 3, '@sui:bank_depositall'))
return
def handleSelection(core, owner, target, option):
if option == RadialOptions.bankitems:
bank = owner.getSlottedObject('bank')
if bank:
core.simulationService.openContainer(owner, bank)
return
+9
View File
@@ -0,0 +1,9 @@
from resources.common import RadialOptions
import sys
def createRadial(core, owner, target, radials):
return
def handleSelection(core, owner, target, option):
return
+5 -2
View File
@@ -28,7 +28,7 @@ import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import resources.common.RadialOptions;
import resources.objects.creature.CreatureObject;
import services.AttributeService;
import services.CharacterService;
@@ -42,6 +42,7 @@ import services.chat.ChatService;
import services.command.CommandService;
import services.object.ObjectService;
import services.object.UpdateService;
import services.sui.SUIService;
import engine.clientdata.ClientFileManager;
import engine.clientdata.visitors.CrcStringTableVisitor;
import engine.clientdata.visitors.DatatableVisitor;
@@ -93,6 +94,7 @@ public class NGECore {
public ScriptService scriptService;
public ChatService chatService;
public AttributeService attributeService;
public SUIService suiService;
// Login Server
@@ -141,7 +143,7 @@ public class NGECore {
commandService = new CommandService(this);
chatService = new ChatService(this);
attributeService = new AttributeService(this);
suiService = new SUIService(this);
// Ping Server
try {
PingServer pingServer = new PingServer(config.getInt("PING.PORT"));
@@ -162,6 +164,7 @@ public class NGECore {
zoneDispatch.addService(objectService);
zoneDispatch.addService(commandService);
zoneDispatch.addService(chatService);
zoneDispatch.addService(suiService);
zoneServer = new MINAServer(zoneDispatch, config.getInt("ZONE.PORT"));
zoneServer.start();
@@ -48,6 +48,7 @@ public class ObjControllerMessage extends SWGMessage {
public static final int COMBAT_SPAM = 0x0134;
public static final int POSTURE = 0x0131;
public static final int SIT_ON_OBJECT = 0x013B;
public static final int OBJECT_MENU_RESPONSE = 0x0147;
public ObjControllerMessage() {
+63
View File
@@ -0,0 +1,63 @@
/*******************************************************************************
* 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 ObjectMenuSelect extends SWGMessage {
private byte selection;
private long objectId;
@Override
public void deserialize(IoBuffer buffer) {
buffer.getShort();
buffer.getInt();
setObjectId(buffer.getLong());
setSelection(buffer.get());
}
@Override
public IoBuffer serialize() {
// TODO Auto-generated method stub
return null;
}
public byte getSelection() {
return selection;
}
public void setSelection(byte selection) {
this.selection = selection;
}
public long getObjectId() {
return objectId;
}
public void setObjectId(long objectId) {
this.objectId = objectId;
}
}
@@ -32,7 +32,7 @@ import engine.resources.scene.Quaternion;
import protocol.swg.ObjControllerMessage;
public class DataTransform extends ObjControllerObject{
public class DataTransform extends ObjControllerObject {
private long objectId;
private int movementIndex;
@@ -0,0 +1,108 @@
/*******************************************************************************
* 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.objectControllerObjects;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Vector;
import org.apache.mina.core.buffer.IoBuffer;
import engine.resources.common.Utilities;
import resources.common.RadialOptions;
public class ObjectMenuRequest extends ObjControllerObject {
private long characterId;
private long targetId;
private Vector<RadialOptions> radialOptions = new Vector<RadialOptions>();
private byte radialCount;
@Override
public void deserialize(IoBuffer buffer) {
setCharacterId(buffer.getLong());
buffer.getInt();
setTargetId(buffer.getLong());
setCharacterId(buffer.getLong());
int listSize = buffer.getInt();
for(int i = 0; i < listSize; i++) {
RadialOptions radial = new RadialOptions();
if(buffer.get() == 0) // option #
return;
radial.setParentId(buffer.get());
radial.setOptionId(buffer.get());
buffer.get();
radial.setOptionType(buffer.get());
int size = buffer.getInt();
if(size > 0) {
try {
radial.setDescription(new String(ByteBuffer.allocate(size * 2).put(buffer.array(), buffer.position(), size * 2).array(), "UTF-16LE"));
buffer.position(buffer.position() + size * 2);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
radial.setDescription("");
}
radialOptions.add(radial);
}
setRadialCount(buffer.get());
}
@Override
public IoBuffer serialize() {
// TODO Auto-generated method stub
return null;
}
public Vector<RadialOptions> getRadialOptions() {
return radialOptions;
}
public long getTargetId() {
return targetId;
}
public void setTargetId(long targetId) {
this.targetId = targetId;
}
public long getCharacterId() {
return characterId;
}
public void setCharacterId(long characterId) {
this.characterId = characterId;
}
public byte getRadialCount() {
return radialCount;
}
public void setRadialCount(byte radialCount) {
this.radialCount = radialCount;
}
}
@@ -0,0 +1,102 @@
/*******************************************************************************
* 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.objectControllerObjects;
import java.nio.ByteOrder;
import java.util.Vector;
import org.apache.mina.core.buffer.IoBuffer;
import engine.resources.common.Utilities;
import protocol.swg.ObjControllerMessage;
import resources.common.RadialOptions;
public class ObjectMenuResponse extends ObjControllerObject {
private long ownerId;
private long targetId;
private Vector<RadialOptions> radialOptions;
private byte radialCount;
public ObjectMenuResponse() {
}
public ObjectMenuResponse(long ownerId, long targetId, Vector<RadialOptions> radialOptions, byte radialCount) {
this.ownerId = ownerId;
this.targetId = targetId;
this.radialOptions = radialOptions;
this.radialCount = radialCount;
}
@Override
public void deserialize(IoBuffer data) {
// TODO Auto-generated method stub
}
@Override
public IoBuffer serialize() {
IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN);
result.setAutoExpand(true);
result.putInt(ObjControllerMessage.OBJECT_MENU_RESPONSE);
result.putLong(ownerId);
result.putInt(0);
result.putLong(targetId);
result.putLong(ownerId);
int size = radialOptions.size();
result.putInt(size);
if(size > 0) {
byte counter = 1;
for(RadialOptions radialOption : radialOptions) {
result.put(counter++);
result.put(radialOption.getParentId());
result.put(radialOption.getOptionId());
result.put((byte) 0);
result.put(radialOption.getOptionType());
if(radialOption.getDescription().length() > 0)
result.put(getUnicodeString(radialOption.getDescription()));
else
result.putInt(0);
}
}
result.put(radialCount);
int packetSize = result.position();
result = IoBuffer.allocate(packetSize).put(result.array(), 0, packetSize);
return result.flip();
}
}
@@ -19,8 +19,24 @@
* 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 services;
package resources.common;
public class SUIService {
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
public class FileUtilities {
public static int getNumberOfLines(String fileName) throws IOException {
LineNumberReader lnr;
lnr = new LineNumberReader(new FileReader(fileName));
lnr.skip(Long.MAX_VALUE);
int numberOfLines = lnr.getLineNumber() + 1;
lnr.close();
return numberOfLines;
}
}
@@ -27,5 +27,6 @@ public class ObjControllerOpcodes {
public static final int DATA_TRANSFORM_WITH_PARENT = 0xF1000000;
public static final int COMMAND_QUEUE_ENQUEUE = 0x16010000;
public static final int TARGET_UPDATE = 0x26010000;
public static final int OBJECT_MENU_REQUEST = 0x46010000;
}
+1
View File
@@ -39,6 +39,7 @@ public class Opcodes {
public static int LagRequest = 0x31805EE0;
public static int LoginClientId = 0x41131F96;
public static int ObjControllerMessage = 0x80CE5E46;
public static int ObjectSelectMenuMessage = 0x7CA18726;
public static int RequestGalaxyLoopTimes = 0x7D842D68;
public static int SelectCharacter = 0xB5098D76;
+328
View File
@@ -0,0 +1,328 @@
/*******************************************************************************
* 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;
public class RadialOptions {
public static int unknown = 0;
public static int combatTarget = 1;
public static int combatUntarget = 2;
public static int combatAttack = 3;
public static int combatPeace = 4;
public static int combatDuel = 5;
public static int combatDeathBlow = 6;
public static int examine = 7;
public static int tradeStart = 8;
public static int tradeAccept = 9;
public static int itemPickup = 10;
public static int itemEquip = 11;
public static int itemUnequip = 12;
public static int itemDrop = 13;
public static int itemDestroy = 14;
public static int itemToken = 15;
public static int itemOpen = 16;
public static int itemOpenNewWindow = 17;
public static int itemActivate = 18;
public static int itemDeactivate = 19;
public static int itemUse = 20;
public static int itemUseSelf = 21;
public static int itemUseOther = 22;
public static int itemSit = 23;
public static int itemMail = 24;
public static int converseStart = 25;
public static int converseRespond = 26;
public static int converseResponse = 27;
public static int converseStop = 28;
public static int craftOptions = 29;
public static int craftStart = 30;
public static int craftHopperInput = 31;
public static int craftHopperOutput = 32;
public static int missionTerminalList = 33;
public static int missionDetails = 34;
public static int loot = 35;
public static int lootAll = 36;
public static int groupInvite = 37;
public static int groupJoin = 38;
public static int groupLeave = 39;
public static int groupKick = 40;
public static int groupDisband = 41;
public static int groupDecline = 42;
public static int extractObject = 43;
public static int petCall = 44;
public static int terminalAuctionUse = 45;
public static int creatureFollow = 46;
public static int creatureStopFollow = 47;
public static int split = 48;
public static int imagedesign = 49;
public static int setName = 50;
public static int itemRotate = 51;
public static int itemRotateRight = 52;
public static int itemRotateLeft = 53;
public static int itemMove = 54;
public static int itemMoveForward = 55;
public static int itemMoveBack = 56;
public static int itemMoveUp = 57;
public static int itemMoveDown = 58;
public static int petStore = 59;
public static int vehicleGenerate = 60;
public static int vehicleStore = 61;
public static int missionAbort = 62;
public static int missionEndDuty = 63;
public static int shipManageComponents = 64;
public static int waypointAutopilot = 65;
public static int programDroid = 66;
public static int serverDivider = 67;
public static int serverMenu1 = 68;
public static int serverMenu2 = 69;
public static int serverMenu3 = 70;
public static int serverMenu4 = 71;
public static int serverMenu5 = 72;
public static int serverMenu6 = 73;
public static int serverMenu7 = 74;
public static int serverMenu8 = 75;
public static int serverMenu9 = 76;
public static int serverMenu10 = 77;
public static int serverHarvesterManage = 78;
public static int serverHouseManage = 79;
public static int serverFactionHallManage = 80;
public static int serverHue = 81;
public static int serverObserve = 82;
public static int serverStopObserving = 83;
public static int serverTravelOptions = 84;
public static int serverBazaarOptions = 85;
public static int serverShippingOptions = 86;
public static int serverHealWound = 87;
public static int serverHealWoundHealth = 88;
public static int serverHealWoundAction = 89;
public static int serverHealWoundStrength = 90;
public static int serverHealWoundConst = 91;
public static int serverHealWoundQuickness = 92;
public static int serverHealWoundStamina = 93;
public static int serverHealDamage = 94;
public static int serverHealState = 95;
public static int serverHealStateStunned = 96;
public static int serverHealStateBlinded = 97;
public static int serverHealStateDizzy = 98;
public static int serverHealStateintim = 99;
public static int serverHealEnhance = 100;
public static int serverHealEnhanceHealth = 101;
public static int serverHealEnhanceAction = 102;
public static int serverHealEnhanceStrangth = 103;
public static int serverHealEnhanceConst = 104;
public static int serverHealEnhanceQuickness = 105;
public static int serverHealEnhanceStamina = 106;
public static int serverHealFirstAid = 107;
public static int serverHealCurePoison = 108;
public static int serverHealCureDisease = 109;
public static int serverHealApplyPoison = 110;
public static int serverHealApplyDisease = 111;
public static int serverHarvestCorpse = 112;
public static int serverPerformanceListen = 113;
public static int serverPerformanceWatch = 114;
public static int serverPerformanceListenStop = 115;
public static int serverPerformanceWatchStop = 116;
public static int serverTerminalPermissions = 117;
public static int serverTerminalManagement = 118;
public static int serverTerminalPermissionsEnter = 119;
public static int serverTerminalPermissionsBanned = 120;
public static int serverTerminalPermissionsAdmin = 121;
public static int serverTerminalPermissionVendor = 122;
public static int serverTerminalPermissionsHopper = 123;
public static int serverTerminalManagementStatus = 124;
public static int serverTerminalManagementPrivacy = 125;
public static int serverTerminalManagementTransfer = 126;
public static int serverTerminalManagementResidence = 127;
public static int serverTerminalManagementDestroy = 128;
public static int serverTerminalManagementPay = 129;
public static int serverTerminalCreateVendor = 130;
public static int serverGiveVendorMaintenance = 131;
public static int serveritemOptions = 132;
public static int serverSurveyToolRange = 133;
public static int serverSurveyToolResolution = 134;
public static int serverSurveyToolClass = 135;
public static int serverProbeDroidTrackTarget = 136;
public static int serverProbeDroidFindTarget = 137;
public static int serverProbeDroidActivate = 138;
public static int serverProbeDroidBuy = 139;
public static int serverTeach = 140;
public static int petCommand = 141;
public static int petFollow = 142;
public static int petStay = 143;
public static int petGuard = 144;
public static int petFriend = 145;
public static int petAttack = 146;
public static int petPatrol = 147;
public static int petGetPatrolPoint = 148;
public static int petClearPatrolPoint = 149;
public static int petAssumeFormation1 = 150;
public static int petAssumeFormation2 = 151;
public static int petTransfer = 152;
public static int petRelease = 153;
public static int petTrick1 = 154;
public static int petTrick2 = 155;
public static int petTrick3 = 156;
public static int petTrick4 = 157;
public static int petGroup = 158;
public static int petTame = 159;
public static int petFeed = 160;
public static int petSpecialAttackOne = 161;
public static int petSpecialAttackTwo = 162;
public static int petRangedAttack = 163;
public static int diceRoll = 164; //Reused for HarvestMeat
public static int diceTwoFace = 165; //Reused for HarvestHide
public static int diceThreeFace = 166; //Reused for HarvestBone
public static int diceFourFace = 167; //Reused for Milk Me
public static int diceFiveFace = 168;
public static int diceSixFace = 169;
public static int diceSevenFace = 170;
public static int diceEightFace = 171;
public static int diceCountOne = 172;
public static int diceCountTwo = 173;
public static int diceCountThree = 174;
public static int diceCountFour = 175;
public static int createBallot = 176;
public static int vote = 177;
public static int bombingRun = 178;
public static int selfDestruct = 179;
public static int thirtySec = 180;
public static int fifteenSec = 181;
public static int serverCampDisband = 182;
public static int serverCampAssumeOwnership = 183;
public static int serverProbeDroidProram = 184;
public static int serverGuildCreate = 185;
public static int serverGuildInfo = 186;
public static int serverGuildMembers = 187;
public static int serverGuildSponsored = 188;
public static int serverGuildEnemies = 189;
public static int serverGuildSponsor = 190;
public static int serverGuildDisband = 191;
public static int serverGuildNameChange = 192;
public static int serverGuildGuildManagement = 193;
public static int serverGuildMemberManagement = 194;
public static int serverManfHopperInput = 195;
public static int serverManfHopperOutput = 196;
public static int serverManfStationSchematic = 197;
public static int elevatorUp = 198;
public static int elevatorDown = 199;
public static int serverPetOpen = 200;
public static int serverPetDpad = 201;
public static int serverMedToolDiagnose = 202;
public static int serverMedToolTendWound = 203;
public static int serverMedToolTendDamage = 204;
public static int serverPetMount = 205;
public static int serverPetDismount = 206;
public static int serverPetTrainMount = 207;
public static int serverVehicleEnter = 208;
public static int serverVehicleExit = 209;
public static int openNaviCompDpad = 210;
public static int initNavicompDpad = 211;
public static int cityStatus = 212;
public static int cityCitizens = 213;
public static int cityStructures = 214;
public static int cityTreasury = 215;
public static int cityManagement = 216;
public static int cityName = 217;
public static int cityMilitia = 218;
public static int cityTaxes = 219;
public static int cityTreasuryDeposit = 220;
public static int cityTreasuryWithdraw = 221;
public static int cityRegister = 222;
public static int cityRank = 223;
public static int cityAdmin1 = 224;
public static int cityAdmin2 = 225;
public static int cityAdmin3 = 226;
public static int cityAdmin4 = 227;
public static int cityAdmin5 = 228;
public static int cityAdmin6 = 229;
public static int memoryChipProgram = 230;
public static int memoryChipTransfer = 231;
public static int memoryChipAnalyze = 232;
public static int equipDroidOnChip = 233;
public static int bankJoin = 234;
public static int bankQuit = 235;
public static int bankDepositAll = 114;
public static int bankWithdrawAll = 115;
public static int bankTransfer = 112;
public static int bankitems = 113;
public static int fireworkshowAdd = 240;
public static int fireworkshowRemove = 241;
public static int fireworkshowModify = 242;
public static int fireworkshowReorder = 243;
public static int fireworkshowData = 244;
public static int operateHarvester = 245;
public static int payMaintenance = 246;
public static int depositPower = 247;
public static int StructureStatus = 248;
public static int StructureOptions = 249;
public static int StartManufacture = 250;
public static int ListIngredients = 251;
public static int StopManufacture = 252;
private byte parentId;
private byte optionId;
private byte optionType;
private String description;
public RadialOptions(byte parentId, byte optionId, byte optionType, String description) {
this.setParentId(parentId);
this.setOptionId(optionId);
this.setOptionType(optionType);
this.setDescription(description);
}
public RadialOptions() {
// TODO Auto-generated constructor stub
}
public byte getParentId() {
return parentId;
}
public void setParentId(byte parentId) {
this.parentId = parentId;
}
public byte getOptionId() {
return optionId;
}
public void setOptionId(byte optionId) {
this.optionId = optionId;
}
public byte getOptionType() {
return optionType;
}
public void setOptionType(byte optionType) {
this.optionType = optionType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
+7 -4
View File
@@ -24,14 +24,16 @@ package resources.objects.guild;
import java.util.ArrayList;
import java.util.List;
import com.sleepycat.persist.model.NotPersistent;
import clients.Client;
import resources.objects.CurrentServerGCWZoneInfo;
import resources.objects.CurrentServerGCWZonePercent;
import resources.objects.Guild;
import resources.objects.OtherServerGCWZonePercent;
import resources.objects.SWGObject;
import com.sleepycat.persist.model.NotPersistent;
import engine.clients.Client;
import engine.resources.objects.SWGObject;
public class GuildObject extends SWGObject {
@@ -309,5 +311,6 @@ public class GuildObject extends SWGObject {
destination.getSession().write(messageBuilder.buildBaseline3());
destination.getSession().write(messageBuilder.buildBaseline6());
}
}
+8
View File
@@ -77,6 +77,14 @@ public class ScriptService {
func.__call__(Py.java2py(arg1), Py.java2py(arg2), Py.java2py(arg3), Py.java2py(arg4));
interpreter.cleanup();
}
public PyObject getMethod(String path, String module, String method) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import sys\nsys.path.append('" + path + "')\nfrom " + module + " import " + method);
PyObject func = interpreter.get(method);
interpreter.cleanup();
return func;
}
}
+31
View File
@@ -22,6 +22,10 @@
package services.object;
import java.io.Console;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.nio.ByteOrder;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -32,6 +36,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
@@ -40,6 +45,8 @@ import resources.common.*;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.python.core.Py;
import org.python.core.PyObject;
import com.sleepycat.persist.EntityCursor;
@@ -89,6 +96,8 @@ public class ObjectService implements INetworkDispatch {
private Random random = new Random();
private Map<String, PyObject> serverTemplates = new ConcurrentHashMap<String, PyObject>();
public ObjectService(final NGECore core) {
this.core = core;
databaseConnection = core.getDatabase1();
@@ -157,7 +166,28 @@ public class ObjectService implements INetworkDispatch {
return null;
}
String serverTemplate = Template.replace(".iff", "");
// check if template is empty(4 default lines) to reduce RAM usage(saves about 500 MB of RAM)
try {
int numberOfLines = FileUtilities.getNumberOfLines("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", "") + serverTemplate.split("shared_" , 2)[1] + ".py");
if(numberOfLines > 4) {
if(serverTemplates.containsKey(Template)) {
PyObject func = serverTemplates.get(Template);
func.__call__(Py.java2py(core), Py.java2py(object));
} else {
PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "setup");
func.__call__(Py.java2py(core), Py.java2py(object));
serverTemplates.put(Template, func);
}
}
} catch (IOException e) {
e.printStackTrace();
}
//core.scriptService.callScript("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), "setup", serverTemplate.split("shared_" , 2)[1], core, object);
object.setPlanetId(planet.getID());
objectList.add(object);
@@ -322,6 +352,7 @@ public class ObjectService implements INetworkDispatch {
creature = (CreatureObject) getObject(objectId);
}
creature.setClient(client);
Point3D position = creature.getPosition();
Planet planet = core.terrainService.getPlanetByID(creature.getPlanetId());
+115 -1
View File
@@ -21,6 +21,120 @@
******************************************************************************/
package services.sui;
public class SUIService {
import java.nio.ByteOrder;
import java.util.Map;
import java.util.Vector;
import main.NGECore;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import protocol.swg.ObjControllerMessage;
import protocol.swg.ObjectMenuSelect;
import protocol.swg.objectControllerObjects.ObjectMenuRequest;
import protocol.swg.objectControllerObjects.ObjectMenuResponse;
import resources.common.ObjControllerOpcodes;
import resources.common.Opcodes;
import resources.common.RadialOptions;
import engine.clients.Client;
import engine.resources.objects.SWGObject;
import engine.resources.service.INetworkDispatch;
import engine.resources.service.INetworkRemoteEvent;
public class SUIService implements INetworkDispatch {
private NGECore core;
public SUIService(NGECore core) {
this.core = core;
}
@Override
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> swgOpcodes, Map<Integer, INetworkRemoteEvent> objControllerOpcodes) {
objControllerOpcodes.put(ObjControllerOpcodes.OBJECT_MENU_REQUEST, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
ObjectMenuRequest request = new ObjectMenuRequest();
request.deserialize(data);
SWGObject target = core.objectService.getObject(request.getTargetId());
SWGObject owner = core.objectService.getObject(request.getCharacterId());
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());
}
});
swgOpcodes.put(Opcodes.ObjectSelectMenuMessage, new INetworkRemoteEvent() {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
data.position(0);
ObjectMenuSelect objMenuSelect = new ObjectMenuSelect();
objMenuSelect.deserialize(data);
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
if(client == null || client.getSession() == null)
return;
SWGObject owner = client.getParent();
SWGObject target = core.objectService.getObject(objMenuSelect.getObjectId());
if(target == null || owner == null)
return;
core.scriptService.callScript("scripts/radial/", getRadialFilename(target), "handleSelection", core, owner, target, objMenuSelect.getSelection());
}
});
}
@Override
public void shutdown() {
// TODO Auto-generated method stub
}
public String getRadialFilename(SWGObject object) {
if(object.getAttachment("radial_filename") != null)
return (String) object.getAttachment("radial_filename");
else
return "default";
}
public void sendRadial(SWGObject owner, SWGObject target, Vector<RadialOptions> radialOptions, byte radialCount) {
ObjectMenuResponse response = new ObjectMenuResponse(owner.getObjectID(), target.getObjectID(), radialOptions, radialCount);
ObjControllerMessage objController = new ObjControllerMessage(0x0B, response);
if(owner.getClient() != null && owner.getClient().getSession() != null)
owner.getClient().getSession().write(objController.serialize());
}
}