mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-09-12 22:45:31 -04:00
Merge pull request #1189 from ilikenwf/master
Database Fixes, Code Cleanups, Removal of Nested loops and if statements that are not necessary
This commit is contained in:
+223
-220
@@ -1,221 +1,224 @@
|
||||
#################
|
||||
## Eclipse
|
||||
#################
|
||||
|
||||
*.pydevproject
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.pkc
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
*.ltn
|
||||
*.pln
|
||||
*.lsb
|
||||
pt_sword_glint
|
||||
*.lod
|
||||
*.msh
|
||||
*.mesh
|
||||
*.iff
|
||||
*.pob
|
||||
*.ws
|
||||
*.trn
|
||||
*.tga
|
||||
*.lmg
|
||||
*.sat
|
||||
*.lay
|
||||
*.flr
|
||||
*.apt
|
||||
*.prt
|
||||
*.cfg
|
||||
*.spr
|
||||
*.swh
|
||||
*.jdb
|
||||
*.lck
|
||||
*.mgn
|
||||
*.0
|
||||
cachedir/
|
||||
appearance/
|
||||
clientdata/
|
||||
*.class
|
||||
|
||||
# SWG Client Folders
|
||||
footprint/
|
||||
interiorlayout/
|
||||
clientdata/quest/
|
||||
|
||||
# PSWG Object Databases
|
||||
odb/building/je.info.*
|
||||
odb/creature/je.info.*
|
||||
odb/doids/je.info.*
|
||||
odb/guild/je.info.*
|
||||
odb/mails/je.info.*
|
||||
odb/oids/je.info.*
|
||||
odb/chatRooms/je.info.*
|
||||
odb/resourcehistory/je.info.*
|
||||
odb/resourceroots/je.info.*
|
||||
odb/resources/je.info.*
|
||||
odb/auction/je.info.*
|
||||
odb/swgobjects/je.info.*
|
||||
odb/bounties/je.info.*
|
||||
odb/cities/je.info.*
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
# Log files
|
||||
#################
|
||||
## Eclipse
|
||||
#################
|
||||
|
||||
*.pydevproject
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.pkc
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
*.ltn
|
||||
*.pln
|
||||
*.lsb
|
||||
pt_sword_glint
|
||||
*.lod
|
||||
*.msh
|
||||
*.mesh
|
||||
*.iff
|
||||
*.pob
|
||||
*.ws
|
||||
*.trn
|
||||
*.tga
|
||||
*.lmg
|
||||
*.sat
|
||||
*.lay
|
||||
*.flr
|
||||
*.apt
|
||||
*.prt
|
||||
*.cfg
|
||||
*.spr
|
||||
*.swh
|
||||
*.jdb
|
||||
*.lck
|
||||
*.mgn
|
||||
*.0
|
||||
cachedir/
|
||||
appearance/
|
||||
clientdata/
|
||||
*.class
|
||||
|
||||
# SWG Client Folders
|
||||
footprint/
|
||||
interiorlayout/
|
||||
clientdata/quest/
|
||||
|
||||
# PSWG Object Databases
|
||||
odb/building/je.info.*
|
||||
odb/creature/je.info.*
|
||||
odb/doids/je.info.*
|
||||
odb/guild/je.info.*
|
||||
odb/mails/je.info.*
|
||||
odb/oids/je.info.*
|
||||
odb/chatRooms/je.info.*
|
||||
odb/resourcehistory/je.info.*
|
||||
odb/resourceroots/je.info.*
|
||||
odb/resources/je.info.*
|
||||
odb/auction/je.info.*
|
||||
odb/swgobjects/je.info.*
|
||||
odb/bounties/je.info.*
|
||||
odb/cities/je.info.*
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
# Log files
|
||||
debuglogs/
|
||||
logs/
|
||||
|
||||
#################
|
||||
## Visual Studio
|
||||
#################
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.vspscc
|
||||
.builds
|
||||
*.dotCover
|
||||
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment this
|
||||
#packages/
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish
|
||||
|
||||
# Others
|
||||
[Bb]in
|
||||
[Oo]bj
|
||||
sql
|
||||
TestResults
|
||||
*.Cache
|
||||
ClientBin
|
||||
stylecop.*
|
||||
~$*
|
||||
*.dbmdl
|
||||
Generated_Code #added for RIA/Silverlight projects
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
|
||||
|
||||
|
||||
############
|
||||
## Windows
|
||||
############
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
|
||||
#############
|
||||
## Python
|
||||
#############
|
||||
|
||||
*.py[co]
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
eggs
|
||||
parts
|
||||
bin
|
||||
var
|
||||
sdist
|
||||
develop-eggs
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
#Translations
|
||||
*.mo
|
||||
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
|
||||
|
||||
#############
|
||||
## PyCharm
|
||||
#############
|
||||
.idea
|
||||
logs/
|
||||
|
||||
#################
|
||||
## Visual Studio
|
||||
#################
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.vspscc
|
||||
.builds
|
||||
*.dotCover
|
||||
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment this
|
||||
#packages/
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish
|
||||
|
||||
# Others
|
||||
[Bb]in
|
||||
[Oo]bj
|
||||
sql
|
||||
TestResults
|
||||
*.Cache
|
||||
ClientBin
|
||||
stylecop.*
|
||||
~$*
|
||||
*.dbmdl
|
||||
Generated_Code #added for RIA/Silverlight projects
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
|
||||
|
||||
|
||||
############
|
||||
## Windows
|
||||
############
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
|
||||
#############
|
||||
## Python
|
||||
#############
|
||||
|
||||
*.py[co]
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
eggs
|
||||
parts
|
||||
bin
|
||||
var
|
||||
sdist
|
||||
develop-eggs
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
#Translations
|
||||
*.mo
|
||||
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
|
||||
|
||||
#############
|
||||
## PyCharm
|
||||
#############
|
||||
.idea
|
||||
|
||||
# The config should be example only
|
||||
nge.cfg
|
||||
|
||||
@@ -1,66 +1,65 @@
|
||||
NGECore2
|
||||
========
|
||||
# NGECore2
|
||||
|
||||
The ProjectSWG Open Source Project's aim is to create a server emulator for the sandbox MMO Star Wars Galaxies at its final publish before
|
||||
shutdown on 15/12/2011.
|
||||
|
||||
The Open Source Version of ProjectSWG is restricted to 30 minutes uptime and upto 5 connections to ensure that the community
|
||||
is not split between several small servers. This restriction will not be lifted, it is also not legal to remove this restriction for anyone(see the engine's license for more legal information).
|
||||
is not split between several small servers. This restriction will not be lifted. It is not legal to remove this restriction, per the license.
|
||||
|
||||
The Engine(NGEngine) is a closed source library and is only licensed for use with this project. The Core(NGECore2) is licensed under the L-GPL License.
|
||||
The Engine (NGEngine) is a closed source library and is only licensed for use with this project. The Core (NGECore2) is licensed under the L-GPL License. By using NGECore2, you agree to the terms of both licenses.
|
||||
|
||||
Requirements for Building the Core:
|
||||
========
|
||||
## Requirements for Building the Core:
|
||||
|
||||
- JDK 8
|
||||
- A Java 8 compatible IDE like Eclipse Kepler (https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler)
|
||||
- A valid Star Wars Galaxies Installation with the final patch
|
||||
- Postgresql server (www.postgresql.org)
|
||||
- TRE Explorer(http://forum.modsource.org/index.php?PHPSESSID=bf02fd8244123807f4716c1686abb59f&action=dlattach;topic=33.0;attach=49)
|
||||
- Github account
|
||||
- (optional for windows) Github for Windows(http://windows.github.com/)
|
||||
* JDK 8
|
||||
* A Java 8 compatible IDE like Eclipse Kepler
|
||||
* https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler
|
||||
* A valid Star Wars Galaxies Installation with the final patch
|
||||
* Postgresql server
|
||||
* http://www.postgresql.org
|
||||
* PGAdmin (optional, but makes managing the database easier)
|
||||
* http://www.pgadmin.org/
|
||||
* TRE Explorer
|
||||
* http://forum.modsource.org/index.php?PHPSESSID=bf02fd8244123807f4716c1686abb59f&action=dlattach;topic=33.0;attach=49
|
||||
* Github account
|
||||
* Github for Windows (optional)
|
||||
* http://windows.github.com/
|
||||
|
||||
Once you have met the requirements, fork the project(click on the fork button) and then clone your forked repository.
|
||||
If you are using Windows then you can clone the repository with Github for Windows, otherwise you can use the following git command:
|
||||
### Setting up the core
|
||||
|
||||
git clone https://github.com/your_account_name/ngecore2.git
|
||||
A video tutorial of this process can be viewed at http://www.projectswg.com/showthread.php?t=40304
|
||||
|
||||
Then you can import the project to Eclipse.
|
||||
1. Once you have met the requirements, fork the project and then proceed to clone your copy of the repository to your computer.
|
||||
2. Import the project to Eclipse.
|
||||
3. Create a postgres DB and restore the nge.backup file. Depending on each update, you may or may not have to repeat this process. Once restored, create an account for yourself in the accounts table of your database, and update the connectionServers table with the appropriate IP address of your server, in the address field.
|
||||
4. Copy nge.cfg.example to nge.cfg, and add your DB credentials and name.
|
||||
5. Create a directory named "clientdata" inside your NGECore2 git repo.
|
||||
5. Open TRE Explorer and proceed open the sku0_client.toc in your SWG directory. Export the following directories to your clientdata directory:
|
||||
|
||||
Next you need to create a postgres DB and restore the nge.backup file. Once you have done that, edit your nge.cfg with your DB information and create an account for yourself in the accounts table of your database.
|
||||
* abstract
|
||||
* appearance
|
||||
* creation
|
||||
* customization
|
||||
* datatables
|
||||
* footprint
|
||||
* interiorlayout
|
||||
* misc
|
||||
* object
|
||||
* quest
|
||||
* snapshot
|
||||
* string
|
||||
* terrain
|
||||
|
||||
Once you've done that open TRE Explorer and open the sku0_client.toc in your SWG folder with it.
|
||||
Repeat the above extraction process with the sku1_client.toc, sku2_client.toc and sku3_client.toc files to avoid errors with kashyyyk.
|
||||
|
||||
Then export the following folders to your clientdata folder(should be located in your project folder):
|
||||
- abstract
|
||||
- appearance
|
||||
- creation
|
||||
- customization
|
||||
- datatables
|
||||
- footprint
|
||||
- interiorlayout
|
||||
- misc
|
||||
- object
|
||||
- quest
|
||||
- snapshot
|
||||
- string
|
||||
- terrain
|
||||
You are now ready to run the core!
|
||||
|
||||
Export the same folders from sku1_client.toc, sku2_client.toc and sku3_client.toc to avoid errors with kashyyyk.
|
||||
## Contributing and Submitting patches
|
||||
|
||||
Now you're ready to run the core!
|
||||
|
||||
Contributing and Submitting patches
|
||||
========
|
||||
|
||||
To contribute, simply commit your changes to your fork of the project and then submit a pull request here:
|
||||
|
||||
https://github.com/ProjectSWGCore/NGECore2/compare/
|
||||
|
||||
Now your changes will be reviewed by other developers and once the changes are approved your code will be merged into the main repository.
|
||||
|
||||
For more information please visit the wiki: https://github.com/ProjectSWGCore/NGECore2/wiki
|
||||
|
||||
Documentation can be found here: http://projectswg.com/doc/
|
||||
To contribute, commit your changes to your fork of the project and then submit a pull request.
|
||||
|
||||
Your changes will be reviewed by other developers. Once the changes are approved, your pull request will be merged into the main repository.
|
||||
|
||||
Please prefix all commits with Added, Changed, Removed or Fixed. If you don't have enough room for multiple changes, use the extended description. Try not to bundle multiple changes into one vague line (ie. "Changed various combat things"). Try to make all commit messages understandable by non-programmers.
|
||||
|
||||
* For more information please visit the wiki at https://github.com/ProjectSWGCore/NGECore2/wiki
|
||||
* Documentation can be found at http://projectswg.com/doc/
|
||||
|
||||
+451
-364
File diff suppressed because it is too large
Load Diff
+117
-118
@@ -28,132 +28,128 @@ import java.nio.ByteOrder;
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
|
||||
public abstract class Message {
|
||||
|
||||
|
||||
protected byte[] data;
|
||||
protected int opcode;
|
||||
protected short sequence;
|
||||
protected IoBuffer result;
|
||||
|
||||
|
||||
public Message() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Message(byte[] data) {
|
||||
this.data = data;
|
||||
|
||||
public Message(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
public int getOpcode() {
|
||||
return opcode;
|
||||
}
|
||||
|
||||
|
||||
public int getSize() {
|
||||
return (data == null) ? 0 : data.length;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getData() {
|
||||
return data == null ? new byte[] { } : data.clone();
|
||||
}
|
||||
|
||||
public abstract void deserialize(IoBuffer data);
|
||||
public abstract IoBuffer serialize();
|
||||
|
||||
protected String getAsciiString(IoBuffer buffer)
|
||||
{
|
||||
return getString(buffer, "US-ASCII");
|
||||
}
|
||||
|
||||
protected String getUnicodeString(IoBuffer buffer)
|
||||
{
|
||||
return getString(buffer, "UTF-16LE");
|
||||
}
|
||||
|
||||
protected byte[] getAsciiString(String string)
|
||||
{
|
||||
return getString(string, "US-ASCII");
|
||||
}
|
||||
|
||||
protected byte[] getUnicodeString(String string)
|
||||
{
|
||||
return getString(string, "UTF-16LE");
|
||||
}
|
||||
|
||||
protected String getString(IoBuffer 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 "";
|
||||
|
||||
}
|
||||
|
||||
//TODO: Verify if character position is set correctly after reading a UTF-16 string
|
||||
buffer.position(bufferPosition + length);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
private 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();
|
||||
|
||||
return data == null ? new byte[] {} : data.clone();
|
||||
}
|
||||
|
||||
//FIXME: this is redundant and was also bugged. At some point, get rid of the redundant functions.
|
||||
public abstract void deserialize(IoBuffer data);
|
||||
|
||||
public abstract IoBuffer serialize();
|
||||
|
||||
protected String getAsciiString(IoBuffer buffer) {
|
||||
return getString(buffer, "US-ASCII");
|
||||
}
|
||||
|
||||
protected String getUnicodeString(IoBuffer buffer) {
|
||||
return getString(buffer, "UTF-16LE");
|
||||
}
|
||||
|
||||
protected byte[] getAsciiString(String string) {
|
||||
return getString(string, "US-ASCII");
|
||||
}
|
||||
|
||||
protected byte[] getUnicodeString(String string) {
|
||||
return getString(string, "UTF-16LE");
|
||||
}
|
||||
|
||||
protected String getString(IoBuffer 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 "";
|
||||
|
||||
}
|
||||
|
||||
// TODO: Verify if character position is set correctly after reading a
|
||||
// UTF-16 string
|
||||
buffer.position(bufferPosition + length);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private 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();
|
||||
|
||||
}
|
||||
|
||||
// FIXME: this is redundant and was also bugged. At some point, get rid of
|
||||
// the redundant functions.
|
||||
/**
|
||||
* Reads the next string in. It gets the length of the
|
||||
* string from the short/int at the beginning of it
|
||||
* @param bb The ByteBuffer to read from
|
||||
* @param charset Charset of the string
|
||||
* Reads the next string in. It gets the length of the string from the
|
||||
* short/int at the beginning of it
|
||||
*
|
||||
* @param bb
|
||||
* The ByteBuffer to read from
|
||||
* @param charset
|
||||
* Charset of the string
|
||||
* @return The read string. Returns "" if exception is thrown
|
||||
*/
|
||||
protected String getNextString(IoBuffer bb, String charset) {
|
||||
@@ -166,7 +162,7 @@ public abstract class Message {
|
||||
}
|
||||
if (length > bb.remaining())
|
||||
return "";
|
||||
byte [] data = new byte[length];
|
||||
byte[] data = new byte[length];
|
||||
bb.get(data);
|
||||
return new String(data, charset);
|
||||
} catch (Exception e) {
|
||||
@@ -174,18 +170,21 @@ public abstract class Message {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the next array with specified size and returns it
|
||||
* @param bb The ByteBuffer to read from
|
||||
* @param size Size of the array
|
||||
*
|
||||
* @param bb
|
||||
* The ByteBuffer to read from
|
||||
* @param size
|
||||
* Size of the array
|
||||
* @return The array that has been read, or an empty array if an exception
|
||||
*/
|
||||
protected byte [] getNextArray(IoBuffer bb, int size) {
|
||||
protected byte[] getNextArray(IoBuffer bb, int size) {
|
||||
try {
|
||||
if (bb.remaining() < size)
|
||||
return new byte[0];
|
||||
byte [] tmp = new byte[size];
|
||||
byte[] tmp = new byte[size];
|
||||
bb.get(tmp);
|
||||
return tmp;
|
||||
} catch (Exception e) {
|
||||
@@ -193,13 +192,13 @@ public abstract class Message {
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected String getNextAsciiString(IoBuffer buffer) {
|
||||
return getNextString(buffer, "US-ASCII");
|
||||
}
|
||||
|
||||
protected String getNextUnicodeString(IoBuffer buffer) {
|
||||
return getNextString(buffer, "UTF-16LE");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+34
-31
@@ -34,107 +34,110 @@ import engine.resources.common.Stf;
|
||||
import engine.resources.objects.SWGObject;
|
||||
|
||||
public abstract class UnitTest extends AbstractUnitTest {
|
||||
|
||||
|
||||
protected NGECore core;
|
||||
|
||||
|
||||
protected IoBuffer buffer = null;
|
||||
|
||||
|
||||
private static CrcStringTableVisitor crcTable = null;
|
||||
|
||||
|
||||
public UnitTest() {
|
||||
super();
|
||||
core = NGECore.getInstance();
|
||||
|
||||
|
||||
if (crcTable == null) {
|
||||
try {
|
||||
crcTable = ClientFileManager.loadFile("misc/object_template_crc_string_table.iff", CrcStringTableVisitor.class);
|
||||
crcTable = ClientFileManager.loadFile(
|
||||
"misc/object_template_crc_string_table.iff",
|
||||
CrcStringTableVisitor.class);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean checkObjectId(long objectId) {
|
||||
Map<Long, String> map = UnitTests.getObjectIdMap();
|
||||
|
||||
|
||||
if (objectId == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
SWGObject object = core.objectService.getObject(objectId);
|
||||
|
||||
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (map.containsKey(objectId)) {
|
||||
if (map.get(objectId) == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!object.getClass().getSimpleName().equals(map.get(objectId))) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
map.put(object.getObjectID(), object.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean checkString(String string) {
|
||||
if (string == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean checkCrc(int crc) {
|
||||
if (crcTable != null) {
|
||||
String template = crcTable.getTemplateString(buffer.getInt());
|
||||
|
||||
|
||||
if (template == null || template.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean checkStf(IoBuffer buffer, boolean failEmpty) {
|
||||
Stf stf = new Stf();
|
||||
String string;
|
||||
|
||||
|
||||
string = getAsciiString(buffer);
|
||||
|
||||
|
||||
if (!checkString(string)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
stf.setStfFilename(string);
|
||||
|
||||
|
||||
if (buffer.getInt() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
string = getAsciiString(buffer);
|
||||
|
||||
|
||||
if (!checkString(string)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
stf.setStfName(string);
|
||||
|
||||
if (stf.getStfFilename().length() == 0 || stf.getStfName().length() == 0) {
|
||||
|
||||
if (stf.getStfFilename().length() == 0
|
||||
|| stf.getStfName().length() == 0) {
|
||||
return !failEmpty;
|
||||
}
|
||||
|
||||
|
||||
if (stf.getStfValue() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -77,22 +77,22 @@ public class BuffBuilder {
|
||||
|
||||
public void setCategory(String category)
|
||||
{
|
||||
this.catId=BuffCategory.MISC;
|
||||
if(category.equals("attributes"))
|
||||
{
|
||||
this.catId=BuffCategory.ATTRIBUTES;
|
||||
}
|
||||
else if(category.equals("trade"))
|
||||
{
|
||||
this.catId=BuffCategory.TRADE;
|
||||
}
|
||||
else if(category.equals("resistances"))
|
||||
{
|
||||
this.catId=BuffCategory.RESISTANCES;
|
||||
}
|
||||
else if(category.equals("combat"))
|
||||
{
|
||||
this.catId=BuffCategory.COMBAT;
|
||||
|
||||
switch (category) {
|
||||
case "attributes":
|
||||
this.catId=BuffCategory.ATTRIBUTES;
|
||||
break;
|
||||
case "trade":
|
||||
this.catId=BuffCategory.TRADE;
|
||||
break;
|
||||
case "resistances":
|
||||
this.catId=BuffCategory.RESISTANCES;
|
||||
break;
|
||||
case "combat":
|
||||
this.catId=BuffCategory.COMBAT;
|
||||
break;
|
||||
default:
|
||||
this.catId=BuffCategory.MISC;
|
||||
}
|
||||
|
||||
this.category = category;
|
||||
|
||||
+507
-421
File diff suppressed because it is too large
Load Diff
@@ -44,7 +44,7 @@ public class AdminService implements INetworkDispatch {
|
||||
PreparedStatement preparedStatement;
|
||||
|
||||
try {
|
||||
preparedStatement = core.getDatabase1().preparedStatement("SELECT * FROM accounts WHERE id=" + id + "");
|
||||
preparedStatement = core.getDatabase1().preparedStatement("SELECT accessLevel FROM accounts WHERE id=" + id);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if(resultSet.next())
|
||||
accessLevel = resultSet.getString("accessLevel");
|
||||
@@ -60,7 +60,7 @@ public class AdminService implements INetworkDispatch {
|
||||
PreparedStatement preparedStatement;
|
||||
|
||||
try {
|
||||
preparedStatement = core.getDatabase1().preparedStatement("SELECT * FROM accounts WHERE id=" + id + "");
|
||||
preparedStatement = core.getDatabase1().preparedStatement("SELECT user FROM accounts WHERE id=" + id);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if(resultSet.next())
|
||||
accountName = resultSet.getString("user");
|
||||
|
||||
@@ -422,7 +422,7 @@ public class CharacterService implements INetworkDispatch {
|
||||
if (isDuplicate) { return true; }
|
||||
|
||||
//FIXME: this is a bit lazy... but it's only temporary :p
|
||||
PreparedStatement psc = databaseConnection.preparedStatement("SELECT * FROM pg_tables WHERE \"tablename\"=?");
|
||||
PreparedStatement psc = databaseConnection.preparedStatement("SELECT COUNT(*) FROM pg_tables WHERE \"tablename\"=?");
|
||||
psc.setString(1, "temp_reserved_char_names");
|
||||
ResultSet resultSetC = psc.executeQuery();
|
||||
boolean tableExists = resultSetC.next();
|
||||
@@ -467,7 +467,7 @@ public class CharacterService implements INetworkDispatch {
|
||||
private String checkForReservedName(String firstName, String lastName) throws SQLException
|
||||
{
|
||||
|
||||
PreparedStatement psc = databaseConnection.preparedStatement("SELECT * FROM pg_tables WHERE \"tablename\"=?");
|
||||
PreparedStatement psc = databaseConnection.preparedStatement("SELECT COUNT(*) FROM pg_tables WHERE \"tablename\"=?");
|
||||
psc.setString(1, "reservednames");
|
||||
ResultSet rsc = psc.executeQuery();
|
||||
if (!rsc.next()) {
|
||||
@@ -485,6 +485,7 @@ public class CharacterService implements INetworkDispatch {
|
||||
String combinedName = firstName + " " + lastName;
|
||||
combinedName.replaceAll("\\s*$", "");
|
||||
|
||||
//we could consider using LIKE here, or some form of regex. either way it doesn't work right at the moment -ilikenwf
|
||||
String query = "SELECT \"type\" FROM \"reservednames\" WHERE (\"match_firstname\" = TRUE AND ? ~ \"pattern\") OR (\"match_both_names\" = TRUE and ? ~ \"pattern\") ";
|
||||
if (lastName != "")
|
||||
{
|
||||
@@ -522,10 +523,12 @@ public class CharacterService implements INetworkDispatch {
|
||||
PreparedStatement preparedStatement;
|
||||
int characters = 0;
|
||||
try {
|
||||
preparedStatement = databaseConnection.preparedStatement("SELECT * FROM characters WHERE \"accountId\"=" + accountId + "");
|
||||
preparedStatement = databaseConnection.preparedStatement("SELECT COUNT(*) AS charCount FROM characters WHERE \"accountId\"=" + accountId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
while(resultSet.next() && !resultSet.isClosed())
|
||||
characters++;
|
||||
|
||||
characters = 0;
|
||||
if (!resultSet.isClosed() && resultSet.next())
|
||||
characters = resultSet.getInt("charCount");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -575,10 +578,10 @@ public class CharacterService implements INetworkDispatch {
|
||||
name = name.toLowerCase();
|
||||
long oid = 0L;
|
||||
try {
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("SELECT * FROM characters WHERE LOWER(\"firstName\")=?");
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("SELECT COUNT(*) AS charCount FROM characters WHERE LOWER(\"firstName\")=?");
|
||||
ps.setString(1, name);
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
if (!resultSet.isClosed() && resultSet.next()) {
|
||||
oid = resultSet.getLong("id");
|
||||
}
|
||||
return oid;
|
||||
@@ -598,7 +601,7 @@ public class CharacterService implements INetworkDispatch {
|
||||
|
||||
String name = "";
|
||||
try {
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("SELECT * FROM characters WHERE \"id\"=?");
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("SELECT firstName FROM characters WHERE \"id\"=?");
|
||||
ps.setLong(1, oid);
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
@@ -609,7 +612,7 @@ public class CharacterService implements INetworkDispatch {
|
||||
}
|
||||
name = name.toLowerCase();
|
||||
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -648,11 +651,11 @@ public class CharacterService implements INetworkDispatch {
|
||||
*/
|
||||
public int getAccountId(long objectId) {
|
||||
try {
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("SELECT * FROM characters WHERE id=?");
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("SELECT accountId FROM characters WHERE id=?");
|
||||
ps.setLong(1, objectId);
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
resultSet.next();
|
||||
return resultSet.getInt("accountId");
|
||||
if (resultSet.next())
|
||||
return resultSet.getInt("accountId");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -84,14 +84,12 @@ public class ConnectionService implements INetworkDispatch {
|
||||
try {
|
||||
synchronized(core.getActiveConnectionsMap()) {
|
||||
for(Client c : core.getActiveConnectionsMap().values()) {
|
||||
if(c.getParent() != null) {
|
||||
if ((System.currentTimeMillis() - c.getSession().getLastReadTime()) > 300000) {
|
||||
try {
|
||||
disconnect(c);
|
||||
} catch (Exception e) {
|
||||
System.err.println("ConnectionService:disconnect(): Error disconnecting client.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if ((c.getParent() != null) && (System.currentTimeMillis() - c.getSession().getLastReadTime()) > 300000) {
|
||||
try {
|
||||
disconnect(c);
|
||||
} catch (Exception e) {
|
||||
System.err.println("ConnectionService:disconnect(): Error disconnecting client.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,15 +128,17 @@ public class ConnectionService implements INetworkDispatch {
|
||||
|
||||
try {
|
||||
|
||||
preparedStatement = databaseConnection.preparedStatement("SELECT * FROM sessions WHERE key=?");
|
||||
preparedStatement = databaseConnection.preparedStatement("SELECT accountId FROM sessions WHERE key=?");
|
||||
preparedStatement.setBytes(1, clientIdMsg.getSessionKey());
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
client.setAccountId(resultSet.getLong("accountId"));
|
||||
long accountId = resultSet.getLong("accountID");
|
||||
|
||||
client.setAccountId(accountId);
|
||||
client.setSessionKey(clientIdMsg.getSessionKey());
|
||||
AccountFeatureBits accountFeatureBits = new AccountFeatureBits();
|
||||
ClientPermissionsMessage clientPermissionsMessage = new ClientPermissionsMessage(maxNumberOfCharacters - core.characterService.getNumberOfCharacters((int) resultSet.getLong("accountId")));
|
||||
ClientPermissionsMessage clientPermissionsMessage = new ClientPermissionsMessage(maxNumberOfCharacters - core.characterService.getNumberOfCharacters((int) accountId));
|
||||
session.write(new HeartBeatMessage().serialize());
|
||||
session.write(accountFeatureBits.serialize());
|
||||
session.write(clientPermissionsMessage.serialize());
|
||||
|
||||
@@ -312,11 +312,13 @@ public class LoginService implements INetworkDispatch{
|
||||
PreparedStatement preparedStatement;
|
||||
|
||||
try {
|
||||
preparedStatement = databaseConnection1.preparedStatement("SELECT * FROM characters WHERE \"accountId\"=" + id + "");
|
||||
preparedStatement = databaseConnection1.preparedStatement("SELECT firstName, lastName, appaearance, id, galaxyId, statusID"
|
||||
+ " FROM characters WHERE \"accountId\"= " + id);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next() && !resultSet.isClosed()) {
|
||||
|
||||
//TODO: on creation just don't allow spaces in first or last name maybe?
|
||||
String characterName = resultSet.getString("firstName").replaceAll("\\s",""); ;
|
||||
String lastName = resultSet.getString("lastName").replaceAll("\\s","");
|
||||
|
||||
@@ -344,7 +346,7 @@ public class LoginService implements INetworkDispatch{
|
||||
LoginEnumCluster servers = new LoginEnumCluster(9);
|
||||
PreparedStatement preparedStatement;
|
||||
try {
|
||||
preparedStatement = databaseConnection1.preparedStatement("SELECT * FROM galaxies");
|
||||
preparedStatement = databaseConnection1.preparedStatement("SELECT id, name FROM galaxies");
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next() && !resultSet.isClosed())
|
||||
servers.addServer(resultSet.getInt("id"), resultSet.getString("name"));
|
||||
@@ -363,7 +365,8 @@ public class LoginService implements INetworkDispatch{
|
||||
LoginClusterStatus clusterStatus = new LoginClusterStatus();
|
||||
ResultSet resultSet;
|
||||
try {
|
||||
PreparedStatement preparedStatement = databaseConnection1.preparedStatement("SELECT * FROM \"connectionServers\"");
|
||||
PreparedStatement preparedStatement = databaseConnection1.preparedStatement("SELECT id, address, port, pingPort, statusID"
|
||||
+ " FROM \"connectionServers\"");
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next() && !resultSet.isClosed())
|
||||
clusterStatus.addServer(
|
||||
|
||||
@@ -719,7 +719,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
customName = customName.split(" ")[0];
|
||||
|
||||
try {
|
||||
PreparedStatement ps = core.getDatabase1().preparedStatement("SELECT * FROM characters WHERE \"firstName\" ILIKE ?");
|
||||
PreparedStatement ps = core.getDatabase1().preparedStatement("SELECT id FROM characters WHERE \"firstName\" ILIKE ?");
|
||||
ps.setString(1, customName);
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user