├── YGCore.v12.suo
├── LoginServer
├── Config
│ ├── setting.ini
│ ├── database.ini
│ ├── network.ini
│ ├── DatabaseStruct.cs
│ ├── SettingStruct.cs
│ ├── NetworkStruct.cs
│ └── Configuration.cs
├── App.config
├── packages.config
├── Network
│ ├── Recv
│ │ ├── RequestServerList.cs
│ │ ├── RequestSelectServer.cs
│ │ └── RequestLogin.cs
│ ├── GameServer
│ │ ├── Send
│ │ │ └── LSReqUserOnlineCount.cs
│ │ ├── GSOpcode.cs
│ │ ├── Recv
│ │ │ ├── GSResUserOnlineCount.cs
│ │ │ └── GSResRegistServer.cs
│ │ ├── GameServerManager.cs
│ │ ├── GSNetworkFactory.cs
│ │ ├── GSASendPacket.cs
│ │ ├── GSARecvPacket.cs
│ │ └── GSClient.cs
│ ├── Send
│ │ ├── ResponseSelectServer.cs
│ │ ├── ResponseServerList.cs
│ │ └── ResponseLogin.cs
│ ├── Opcode.cs
│ ├── ClientManager.cs
│ ├── NetworkFactory.cs
│ ├── ASendPacket.cs
│ ├── ARecvPacket.cs
│ └── Client.cs
├── Model
│ └── Account
│ │ └── Account.cs
├── Properties
│ └── AssemblyInfo.cs
├── LoginServer.cs
├── Database
│ └── MdbAccount.cs
├── Service
│ └── AuthService.cs
└── LoginServer.csproj
├── packages
├── NLog.2.1.0
│ ├── NLog.2.1.0.nupkg
│ ├── lib
│ │ ├── sl2
│ │ │ └── NLog.dll
│ │ ├── sl3
│ │ │ └── NLog.dll
│ │ ├── sl4
│ │ │ └── NLog.dll
│ │ ├── sl5
│ │ │ └── NLog.dll
│ │ ├── net20
│ │ │ └── NLog.dll
│ │ ├── net35
│ │ │ └── NLog.dll
│ │ ├── net40
│ │ │ └── NLog.dll
│ │ ├── net45
│ │ │ └── NLog.dll
│ │ ├── sl3-wp
│ │ │ └── NLog.dll
│ │ └── sl4-windowsphone71
│ │ │ └── NLog.dll
│ ├── tools
│ │ ├── sl4
│ │ │ └── InstallNLogConfig.exe
│ │ ├── sl5
│ │ │ └── InstallNLogConfig.exe
│ │ ├── net20
│ │ │ └── InstallNLogConfig.exe
│ │ ├── net35
│ │ │ └── InstallNLogConfig.exe
│ │ ├── net40
│ │ │ └── InstallNLogConfig.exe
│ │ └── net45
│ │ │ └── InstallNLogConfig.exe
│ └── NLog.2.1.0.nuspec
├── Trove.Nini.1.1.0.0
│ ├── lib
│ │ └── net20
│ │ │ └── Nini.dll
│ ├── Trove.Nini.1.1.0.0.nupkg
│ └── Trove.Nini.1.1.0.0.nuspec
├── protobuf-net.2.0.0.668
│ ├── lib
│ │ ├── sl4
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── net20
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── net30
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── net35
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── net40
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── sl3-wp
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── net20-cf
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── net35-cf
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── net40-cf
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── netcore45
│ │ │ ├── protobuf-net.dll
│ │ │ ├── protobuf-net.pdb
│ │ │ └── protobuf-net.pri
│ │ ├── windowsphone8
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ ├── sl4-windowsphone71
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ │ └── portable-sl4+net40+wp7+windows8
│ │ │ ├── protobuf-net.dll
│ │ │ └── protobuf-net.pdb
│ ├── protobuf-net.2.0.0.668.nupkg
│ └── protobuf-net.2.0.0.668.nuspec
├── mongocsharpdriver.1.9.0
│ ├── lib
│ │ └── net35
│ │ │ ├── MongoDB.Bson.dll
│ │ │ └── MongoDB.Driver.dll
│ ├── mongocsharpdriver.1.9.0.nupkg
│ ├── mongocsharpdriver.1.9.0.nuspec
│ └── License.rtf
└── repositories.config
├── GameServer
├── Config
│ ├── database.ini
│ ├── setting.ini
│ ├── channel.ini
│ ├── network.ini
│ ├── DatabaseStruct.cs
│ ├── NetworkStruct.cs
│ ├── SettingStruct.cs
│ └── Configuration.cs
├── Model
│ ├── Character
│ │ ├── CharacterGender.cs
│ │ ├── CharacterClass.cs
│ │ └── Character.cs
│ ├── GameObject.cs
│ ├── Item
│ │ ├── StorageType.cs
│ │ ├── StorageItem.cs
│ │ └── Storage.cs
│ ├── Map
│ │ ├── Map.cs
│ │ └── MapPosition.cs
│ ├── Account
│ │ ├── Account.cs
│ │ └── AccountSetting.cs
│ └── Creature
│ │ ├── Creature.cs
│ │ ├── CreatureBaseStats.cs
│ │ └── CreatureLifeStats.cs
├── App.config
├── Network
│ ├── Send
│ │ ├── ResponseRunning.cs
│ │ ├── ResponseExit.cs
│ │ ├── ResponseInitGame.cs
│ │ ├── ResponseServerTime.cs
│ │ ├── ResponseCreateCharacter.cs
│ │ ├── ResponseCheckName.cs
│ │ ├── ResponseDeleteCharacter.cs
│ │ ├── ResponseSetBuff.cs
│ │ ├── ResponseAuth.cs
│ │ ├── ResponseCharacterList.cs
│ │ └── ResponseCharacterInfo.cs
│ ├── Recv
│ │ ├── RequestExit.cs
│ │ ├── RequestUseSkill.cs
│ │ ├── RequestCheckName.cs
│ │ ├── RequestInitGame.cs
│ │ ├── RequestCharacterList.cs
│ │ ├── RequestEntergame.cs
│ │ ├── RequestDeleteCharacter.cs
│ │ ├── RequestCreateCharacter.cs
│ │ └── RequestAuth.cs
│ ├── LoginServer
│ │ ├── Recv
│ │ │ └── LSReqUserOnlineCount.cs
│ │ ├── LSOpcode.cs
│ │ ├── Send
│ │ │ ├── GSResUserOnlineCount.cs
│ │ │ └── GSReqRegistServer.cs
│ │ ├── LSASendPacket.cs
│ │ ├── LSARecvPacket.cs
│ │ └── LSClient.cs
│ ├── NetworkFactory.cs
│ ├── Opcode.cs
│ ├── ClientManager.cs
│ ├── ARecvPacket.cs
│ ├── ASendPacket.cs
│ └── Client.cs
├── packages.config
├── Service
│ ├── AuthService.cs
│ ├── MapService.cs
│ ├── CharacterService.cs
│ └── StatsService.cs
├── Properties
│ └── AssemblyInfo.cs
├── GameServer.cs
├── Database
│ ├── MdbAccount.cs
│ └── MdbCharacter.cs
├── DataHolder
│ └── Data.cs
└── GameServer.csproj
├── Common
├── packages.config
├── Model
│ └── Server
│ │ ├── ChannelStruct.cs
│ │ └── ServerStruct.cs
├── NLog.config
├── Properties
│ └── AssemblyInfo.cs
├── Utilities
│ ├── IDFactory.cs
│ ├── Log.cs
│ └── Funcs.cs
└── Common.csproj
├── README.md
└── YGCore.sln
/YGCore.v12.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/YGCore.v12.suo
--------------------------------------------------------------------------------
/LoginServer/Config/setting.ini:
--------------------------------------------------------------------------------
1 | [setting]
2 | debuging = true
3 | autoaccount = true
4 | gmonly = false
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/NLog.2.1.0.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/NLog.2.1.0.nupkg
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/sl2/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/sl2/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/sl3/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/sl3/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/sl4/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/sl4/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/sl5/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/sl5/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/net20/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/net20/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/net35/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/net35/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/net40/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/net40/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/net45/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/net45/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/sl3-wp/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/sl3-wp/NLog.dll
--------------------------------------------------------------------------------
/packages/Trove.Nini.1.1.0.0/lib/net20/Nini.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/Trove.Nini.1.1.0.0/lib/net20/Nini.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/lib/sl4-windowsphone71/NLog.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/lib/sl4-windowsphone71/NLog.dll
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/tools/sl4/InstallNLogConfig.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/tools/sl4/InstallNLogConfig.exe
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/tools/sl5/InstallNLogConfig.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/tools/sl5/InstallNLogConfig.exe
--------------------------------------------------------------------------------
/packages/Trove.Nini.1.1.0.0/Trove.Nini.1.1.0.0.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/Trove.Nini.1.1.0.0/Trove.Nini.1.1.0.0.nupkg
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/tools/net20/InstallNLogConfig.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/tools/net20/InstallNLogConfig.exe
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/tools/net35/InstallNLogConfig.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/tools/net35/InstallNLogConfig.exe
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/tools/net40/InstallNLogConfig.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/tools/net40/InstallNLogConfig.exe
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/tools/net45/InstallNLogConfig.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/NLog.2.1.0/tools/net45/InstallNLogConfig.exe
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/sl4/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/sl4/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/sl4/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/sl4/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/mongocsharpdriver.1.9.0/lib/net35/MongoDB.Bson.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/mongocsharpdriver.1.9.0/lib/net35/MongoDB.Bson.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net20/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net20/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net20/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net20/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net30/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net30/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net30/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net30/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net35/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net35/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net35/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net35/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net40/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net40/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net40/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net40/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/sl3-wp/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/sl3-wp/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/sl3-wp/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/sl3-wp/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/mongocsharpdriver.1.9.0/lib/net35/MongoDB.Driver.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/mongocsharpdriver.1.9.0/lib/net35/MongoDB.Driver.dll
--------------------------------------------------------------------------------
/packages/mongocsharpdriver.1.9.0/mongocsharpdriver.1.9.0.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/mongocsharpdriver.1.9.0/mongocsharpdriver.1.9.0.nupkg
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net20-cf/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net20-cf/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net20-cf/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net20-cf/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net35-cf/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net35-cf/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net35-cf/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net35-cf/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net40-cf/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net40-cf/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/net40-cf/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/net40-cf/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/netcore45/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/netcore45/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/netcore45/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/netcore45/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/netcore45/protobuf-net.pri:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/netcore45/protobuf-net.pri
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/protobuf-net.2.0.0.668.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/protobuf-net.2.0.0.668.nupkg
--------------------------------------------------------------------------------
/GameServer/Config/database.ini:
--------------------------------------------------------------------------------
1 | ; Database is base on mongodb
2 | ; https://www.mongodb.org
3 | [database]
4 | db.mongo.url = mongodb://localhost
5 | db.mongo.name = yulgang_database
--------------------------------------------------------------------------------
/LoginServer/Config/database.ini:
--------------------------------------------------------------------------------
1 | ; Database is base on mongodb
2 | ; https://www.mongodb.org
3 | [database]
4 | db.mongo.url = mongodb://localhost
5 | db.mongo.name = yulgang_database
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/windowsphone8/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/windowsphone8/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/windowsphone8/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/windowsphone8/protobuf-net.pdb
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/sl4-windowsphone71/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/sl4-windowsphone71/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/sl4-windowsphone71/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/sl4-windowsphone71/protobuf-net.pdb
--------------------------------------------------------------------------------
/GameServer/Model/Character/CharacterGender.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Model.Character
2 | {
3 | public enum CharacterGender : byte
4 | {
5 | Male = 0,
6 | Female = 1,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/GameServer/Model/GameObject.cs:
--------------------------------------------------------------------------------
1 | using MongoDB.Bson;
2 |
3 | namespace GameServer.Model
4 | {
5 | public abstract class GameObject
6 | {
7 | public ObjectId Id;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/portable-sl4+net40+wp7+windows8/protobuf-net.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/portable-sl4+net40+wp7+windows8/protobuf-net.dll
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/lib/portable-sl4+net40+wp7+windows8/protobuf-net.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ygcore/server/HEAD/packages/protobuf-net.2.0.0.668/lib/portable-sl4+net40+wp7+windows8/protobuf-net.pdb
--------------------------------------------------------------------------------
/GameServer/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LoginServer/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Common/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/GameServer/Model/Item/StorageType.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Model.Item
2 | {
3 | public enum StorageType
4 | {
5 | Inventory,
6 | Equipment,
7 | Warehouse,
8 | AccountWarehouse,
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/GameServer/Config/setting.ini:
--------------------------------------------------------------------------------
1 | [setting]
2 | ; server info
3 | server.id = 1
4 | server.name = test server
5 | server.Akey = false
6 |
7 | ; debuging
8 | debuging = true
9 |
10 | ; server rate
11 | rate.exp = 1
12 | rate.money = 1
13 | rate.sp = 1
--------------------------------------------------------------------------------
/GameServer/Config/channel.ini:
--------------------------------------------------------------------------------
1 | [channel1]
2 | channel.port = 16101
3 | channel.name = test channel
4 | channel.type = 0
5 | channel.max = 100
6 |
7 | [channel2]
8 | channel.port = 16102
9 | channel.name = test channel 2
10 | channel.type = 1
11 | channel.max = 100
12 |
--------------------------------------------------------------------------------
/LoginServer/Config/network.ini:
--------------------------------------------------------------------------------
1 | [network]
2 | ; public is for client connect
3 | public.ip = 127.0.0.1
4 | public.port = 16000
5 |
6 | ; private is for server connect to server
7 | ; such as game server connect to login server
8 | private.ip = 127.0.0.1
9 | private.port = 15000
--------------------------------------------------------------------------------
/packages/repositories.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseRunning.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace GameServer.Network.Send
3 | {
4 | public class ResponseRunning : ASendPacket
5 | {
6 | protected internal override void Write()
7 | {
8 | WriteD(1);
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/GameServer/Model/Item/StorageItem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace GameServer.Model.Item
8 | {
9 | public class StorageItem
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/GameServer/Config/network.ini:
--------------------------------------------------------------------------------
1 | [network]
2 | public.ip = 127.0.0.1
3 |
4 | ; ip for listening third party connection
5 | ; such as administrator monitor tool
6 | private.ip = 127.0.0.1
7 | private.port = 15100
8 |
9 | ; ip to connect login server
10 | login.ip = 127.0.0.1
11 | login.port = 15000
--------------------------------------------------------------------------------
/GameServer/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LoginServer/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GameServer/Model/Character/CharacterClass.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Model.Character
2 | {
3 | public enum CharacterClass
4 | {
5 | Blademan = 1,
6 | Swordman = 2,
7 | Spearman = 3,
8 | Bowman = 4,
9 | Medic = 5,
10 | Ninja = 6,
11 | Busker = 7,
12 | Hanbi = 8,
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/GameServer/Config/DatabaseStruct.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Config
2 | {
3 | public struct DatabaseStruct
4 | {
5 | public string Url;
6 |
7 | public string Name;
8 |
9 | public DatabaseStruct(string url, string name)
10 | {
11 | Url = url;
12 | Name = name;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/LoginServer/Config/DatabaseStruct.cs:
--------------------------------------------------------------------------------
1 | namespace LoginServer.Config
2 | {
3 | public struct DatabaseStruct
4 | {
5 | public string Url;
6 |
7 | public string Name;
8 |
9 | public DatabaseStruct(string url, string name)
10 | {
11 | Url = url;
12 | Name = name;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseExit.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Network.Send
2 | {
3 | public class ResponseExit : ASendPacket
4 | {
5 | protected internal override void Write()
6 | {
7 | WriteD(1);
8 | WriteB(new byte[18]);
9 | WriteS(_Client._Account.Name.ToUpper(), 20);
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseInitGame.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace GameServer.Network.Send
8 | {
9 | public class ResponseInitGame : ASendPacket
10 | {
11 | protected internal override void Write()
12 | {
13 |
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | YGCore Server
2 | ======
3 |
4 | Yulgang Core Emulator in .Net Framework 4.X
5 |
6 | Language: C# .Net Framework 4.X
7 | Database: MongoDB
8 | Logger: NLog
9 | Ini Reader: Nini
10 | File Serializer: protobuf-net
11 |
12 |
13 | ======
14 |
15 | Server Compatible with Yulgang Client 10.40 and latest
16 |
17 | Project forum: http://www.ygcore.org
18 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestExit.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Network.Send;
2 |
3 | namespace GameServer.Network.Recv
4 | {
5 | public class RequestExit : ARecvPacket
6 | {
7 | protected internal override void Read()
8 | {
9 |
10 | }
11 |
12 | protected internal override void Run()
13 | {
14 | _Client.SendPacket(new ResponseExit());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseServerTime.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace GameServer.Network.Send
3 | {
4 | public class ResponseServerTime : ASendPacket
5 | {
6 | protected int Time;
7 |
8 | public ResponseServerTime(int time)
9 | {
10 | Time = time;
11 | }
12 |
13 | protected internal override void Write()
14 | {
15 | WriteD(Time);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/GameServer/Model/Map/Map.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System.Collections.Generic;
3 |
4 | namespace GameServer.Model.Map
5 | {
6 | public class Map
7 | {
8 | public int MapId;
9 |
10 | public IDFactory NpcUID = new IDFactory(10000);
11 | public IDFactory DropUID = new IDFactory(20000);
12 |
13 | public List Characters = new List();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/LoginServer/Config/SettingStruct.cs:
--------------------------------------------------------------------------------
1 | namespace LoginServer.Config
2 | {
3 | public struct SettingStruct
4 | {
5 | public bool Debug;
6 |
7 | public bool AutoAccount;
8 |
9 | public bool GMOnly;
10 |
11 | public SettingStruct(bool debug, bool auto, bool gm)
12 | {
13 | Debug = debug;
14 | AutoAccount = auto;
15 | GMOnly = gm;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseCreateCharacter.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace GameServer.Network.Send
3 | {
4 | public class ResponseCreateCharacter : ASendPacket
5 | {
6 | protected int result;
7 |
8 | public ResponseCreateCharacter(int res)
9 | {
10 | result = res;
11 | }
12 |
13 | protected internal override void Write()
14 | {
15 | WriteD(result);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/LoginServer/Network/Recv/RequestServerList.cs:
--------------------------------------------------------------------------------
1 | using LoginServer.Network.Send;
2 |
3 | namespace LoginServer.Network.Recv
4 | {
5 | public class RequestServerList : ARecvPacket
6 | {
7 | protected internal override void Read()
8 | {
9 |
10 | }
11 |
12 | protected internal override void Run()
13 | {
14 | _Client.SendPacket(new ResponseServerList());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/GameServer/Model/Map/MapPosition.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Model.Map
2 | {
3 | public class MapPosition
4 | {
5 | public int MapId { get; set; }
6 |
7 | public byte[] X { get; set; }
8 |
9 | public byte[] Y { get; set; }
10 |
11 | public byte[] Z { get; set; }
12 |
13 | public byte[] oldX { get; set; }
14 |
15 | public byte[] oldY { get; set; }
16 |
17 | public byte[] oldZ { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/LoginServer/Model/Account/Account.cs:
--------------------------------------------------------------------------------
1 | using MongoDB.Bson;
2 |
3 | namespace LoginServer.Model.Account
4 | {
5 | public class Account
6 | {
7 | public ObjectId Id { get; set; }
8 |
9 | public string Name { get; set; }
10 |
11 | public string Password { get; set; }
12 |
13 | public string LastAddress { get; set; }
14 |
15 | public bool HasAKey { get; set; }
16 |
17 | public string DeletePasswd { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/LoginServer/Config/NetworkStruct.cs:
--------------------------------------------------------------------------------
1 | namespace LoginServer.Config
2 | {
3 | public struct NetworkStruct
4 | {
5 | public string PublicIp;
6 |
7 | public int PublicPort;
8 |
9 | public string PrivateIp;
10 |
11 | public int PrivatePort;
12 |
13 | public NetworkStruct(string ip1, int port1, string ip2, int port2)
14 | {
15 | PublicIp = ip1;
16 | PublicPort = port1;
17 | PrivateIp = ip2;
18 | PrivatePort = port2;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/Send/LSReqUserOnlineCount.cs:
--------------------------------------------------------------------------------
1 | using ProtoBuf;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace LoginServer.Network.GameServer.Send
10 | {
11 | public class LSReqUserOnlineCount : GSASendPacket
12 | {
13 | public LSReqUserOnlineCount()
14 | {
15 |
16 | }
17 |
18 | protected internal override void Write()
19 | {
20 |
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestUseSkill.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Network.Recv
2 | {
3 | public class RequestUseSkill : ARecvPacket
4 | {
5 | protected int SkillId;
6 |
7 | protected internal override void Read()
8 | {
9 | SkillId = ReadD();
10 | //ReadQ(); // unk
11 | //Log.Debug("X:{0}, Z:{1}, Y:{2}", ReadF(), ReadF(), ReadF());
12 | //ReadD();
13 | }
14 |
15 | protected internal override void Run()
16 | {
17 |
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestCheckName.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Service;
2 | using System.Text;
3 |
4 | namespace GameServer.Network.Recv
5 | {
6 | public class RequestCheckName : ARecvPacket
7 | {
8 | protected string Name;
9 |
10 | protected internal override void Read()
11 | {
12 | Name = Encoding.Default.GetString(ReadB(15));
13 | }
14 |
15 | protected internal override void Run()
16 | {
17 | CharacterService.GetInstance().SendCheckName(_Client._Account, Name);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestInitGame.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Network.Send;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace GameServer.Network.Recv
9 | {
10 | public class RequestInitGame : ARecvPacket
11 | {
12 | protected internal override void Read()
13 | {
14 |
15 | }
16 |
17 | protected internal override void Run()
18 | {
19 | new ResponseInitGame().Send(_Client);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/GameServer/Network/LoginServer/Recv/LSReqUserOnlineCount.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using GameServer.Network.LoginServer.Send;
3 | using ProtoBuf;
4 | using System.Collections.Generic;
5 | using System.IO;
6 |
7 | namespace GameServer.Network.LoginServer.Recv
8 | {
9 | public class LSReqUserOnlineCount : LSARecvPacket
10 | {
11 | protected internal override void Read()
12 | {
13 |
14 | }
15 |
16 | protected internal override void Run()
17 | {
18 | _Client.SendPacket(new GSResUserOnlineCount());
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseCheckName.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Network.Send
2 | {
3 | public class ResponseCheckName : ASendPacket
4 | {
5 | protected string Name;
6 | protected short Result;
7 |
8 | public ResponseCheckName(string name, bool res)
9 | {
10 | Name = name;
11 | Result = (short)((res == true) ? 1 : 0);
12 | }
13 |
14 | protected internal override void Write()
15 | {
16 | WriteH((short)Result);
17 | WriteH(0);
18 | WriteS(Name, 15);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/GameServer/Config/NetworkStruct.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Config
2 | {
3 | public struct NetworkStruct
4 | {
5 | public string PublicIp;
6 |
7 | public string PrivateIp;
8 |
9 | public int PrivatePort;
10 |
11 | public string LoginIp;
12 |
13 | public int LoginPort;
14 |
15 | public NetworkStruct(string ip1, string ip2, int port2, string ip3, int port3)
16 | {
17 | PublicIp = ip1;
18 | PrivateIp = ip2;
19 | PrivatePort = port2;
20 | LoginIp = ip3;
21 | LoginPort = port3;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/GameServer/Service/AuthService.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Database;
2 | using GameServer.Model.Account;
3 |
4 | namespace GameServer.Service
5 | {
6 | public class AuthService
7 | {
8 | private static AuthService Instance;
9 |
10 | public static AuthService GetInstance()
11 | {
12 | return (Instance != null) ? Instance : Instance = new AuthService();
13 | }
14 |
15 | public Account AuthAccount(string login, string password)
16 | {
17 | var account = MdbAccount.GetInstance().GetAccountByName(login);
18 | return (account != null) ? account : null;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Common/Model/Server/ChannelStruct.cs:
--------------------------------------------------------------------------------
1 | namespace Common.Model.Server
2 | {
3 | public struct ChannelStruct
4 | {
5 | public int Id;
6 |
7 | public string Name;
8 |
9 | public int Port;
10 |
11 | public int Type;
12 |
13 | public int MaxUser;
14 |
15 | public int CurrentUser;
16 |
17 | public ChannelStruct(int id, string name, int port, int type, int maxuser, int curr = 0)
18 | {
19 | Id = id;
20 | Name = name;
21 | Port = port;
22 | Type = type;
23 | MaxUser = maxuser;
24 | CurrentUser = curr;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/GameServer/Service/MapService.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Model.Map;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace GameServer.Service
9 | {
10 | public class MapService
11 | {
12 | private static MapService Instance;
13 |
14 | public Dictionary Maps = new Dictionary();
15 |
16 | public MapService()
17 | {
18 |
19 | }
20 |
21 | public static MapService GetInstance()
22 | {
23 | return (Instance != null) ? Instance : Instance = new MapService();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestCharacterList.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Database;
2 | using GameServer.Model.Character;
3 | using GameServer.Service;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace GameServer.Network.Recv
11 | {
12 | public class RequestCharacterList : ARecvPacket
13 | {
14 | protected internal override void Read()
15 | {
16 |
17 | }
18 |
19 | protected internal override void Run()
20 | {
21 | CharacterService.GetInstance().SendCharacterList(_Client._Account);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Common/Model/Server/ServerStruct.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Common.Model.Server
4 | {
5 | public struct ServerStruct
6 | {
7 | public int Id;
8 |
9 | public string Name;
10 |
11 | public string Address;
12 |
13 | public bool IsUseAtKey;
14 |
15 | public Dictionary Channels;
16 |
17 | public ServerStruct(int id, string name, string addr, bool usekey)
18 | {
19 | Id = id;
20 | Name = name;
21 | Address = addr;
22 | IsUseAtKey = usekey;
23 | Channels = new Dictionary();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseDeleteCharacter.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Network.Send
2 | {
3 | public class ResponseDeleteCharacter : ASendPacket
4 | {
5 | protected bool Success;
6 |
7 | public ResponseDeleteCharacter(bool success)
8 | {
9 | Success = success;
10 | }
11 |
12 | protected internal override void Write()
13 | {
14 | if (Success)
15 | {
16 | WriteD(1);
17 | WriteD(0);
18 | }
19 | else
20 | {
21 | WriteD(99);
22 | WriteD(9);
23 | }
24 |
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestEntergame.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Service;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace GameServer.Network.Recv
9 | {
10 | public class RequestEntergame : ARecvPacket
11 | {
12 | protected int charIndex;
13 | protected internal override void Read()
14 | {
15 | charIndex = ReadC();
16 | }
17 |
18 | protected internal override void Run()
19 | {
20 | _Client._Char = _Client._Account._Characters[charIndex];
21 | CharacterService.GetInstance().CharacterEnterGame(_Client);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestDeleteCharacter.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Service;
2 |
3 | namespace GameServer.Network.Recv
4 | {
5 | public class RequestDeleteCharacter : ARecvPacket
6 | {
7 | protected string deletepw;
8 | protected string charname;
9 |
10 | protected internal override void Read()
11 | {
12 | ReadD();
13 | long unk1 = ReadQ();
14 | deletepw = ReadS(10);
15 | ReadB(30);
16 | charname = ReadS(16).Replace("\0", "");
17 | }
18 |
19 | protected internal override void Run()
20 | {
21 | CharacterService.GetInstance().DeleteCharacter(_Client._Account, deletepw, charname);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/LoginServer/Network/Send/ResponseSelectServer.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using System.Linq;
3 |
4 | namespace LoginServer.Network.Send
5 | {
6 | public class ResponseSelectServer : ASendPacket
7 | {
8 | protected ServerStruct server;
9 | protected ChannelStruct channel;
10 |
11 | public ResponseSelectServer(int sid, int cid)
12 | {
13 | server = LoginServer.ServerList[sid];
14 | channel = server.Channels[cid];
15 | }
16 |
17 | protected internal override void Write()
18 | {
19 | WriteS(server.Address);
20 | WriteH(channel.Port);
21 | WriteS(channel.Name);
22 | WriteS(channel.Name);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/GameServer/Network/LoginServer/LSOpcode.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Network.LoginServer.Recv;
2 | using GameServer.Network.LoginServer.Send;
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace GameServer.Network.LoginServer
7 | {
8 | public class LSOpcode
9 | {
10 | public static Dictionary Recv = new Dictionary();
11 | public static Dictionary Send = new Dictionary();
12 |
13 | public static void Init()
14 | {
15 | Recv.Add(unchecked((short)0x0002), typeof(LSReqUserOnlineCount));
16 |
17 |
18 | Send.Add(typeof(GSReqRegistServer), unchecked((short)0x0001));
19 | Send.Add(typeof(GSResUserOnlineCount), unchecked((short)0x1001));
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/GSOpcode.cs:
--------------------------------------------------------------------------------
1 | using LoginServer.Network.GameServer.Recv;
2 | using LoginServer.Network.GameServer.Send;
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace LoginServer.Network.GameServer
7 | {
8 | public class GSOpcode
9 | {
10 | public static Dictionary Recv = new Dictionary();
11 | public static Dictionary Send = new Dictionary();
12 |
13 | public static void Init()
14 | {
15 | Recv.Add(unchecked((short)0x0001), typeof(GSResRegistServer));
16 | Recv.Add(unchecked((short)0x1001), typeof(GSResUserOnlineCount));
17 |
18 |
19 | Send.Add(typeof(LSReqUserOnlineCount), unchecked((short)0x0002));
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseSetBuff.cs:
--------------------------------------------------------------------------------
1 | namespace GameServer.Network.Send
2 | {
3 | public class ResponseSetBuff : ASendPacket
4 | {
5 | protected int SkillID;
6 | protected byte Cmd;
7 | protected byte SkillLevel;
8 |
9 | public ResponseSetBuff(int skill, byte cmd, int level)
10 | {
11 | SkillID = skill;
12 | Cmd = cmd;
13 | SkillLevel = (byte)level;
14 | }
15 |
16 | protected internal override void Write()
17 | {
18 | WriteD(SkillID);
19 | WriteC(Cmd);
20 | WriteC(SkillLevel);
21 | WriteH(0);
22 | WriteD(0);
23 | WriteD(0);
24 | WriteD(0);
25 | WriteD(0);
26 | WriteD(3000);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/GameServer/Model/Account/Account.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Network;
2 | using MongoDB.Bson;
3 | using MongoDB.Bson.Serialization.Attributes;
4 | using System.Collections.Generic;
5 |
6 | namespace GameServer.Model.Account
7 | {
8 | public class Account
9 | {
10 | public ObjectId Id { get; set; }
11 |
12 | public string Name { get; set; }
13 |
14 | public string Password { get; set; }
15 |
16 | public string LastAddress { get; set; }
17 |
18 | public bool HasAKey { get; set; }
19 |
20 | public string DeletePasswd { get; set; }
21 |
22 | public AccountSetting Setting { get; set; }
23 |
24 | [BsonIgnore]
25 | public Client _Client { get; set; }
26 |
27 | [BsonIgnore]
28 | public Dictionary _Characters { get; set; }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/GameServer/Config/SettingStruct.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace GameServer.Config
8 | {
9 | public struct SettingStruct
10 | {
11 | public int ServerId;
12 | public string ServerName;
13 | public bool UseAKey;
14 |
15 | public bool Debug;
16 |
17 | public int RateExp;
18 | public int RateMoney;
19 | public int RateSp;
20 |
21 | public SettingStruct(int svId, string svName, bool useAkey, bool debug, int exp, int money, int sp)
22 | {
23 | ServerId = svId;
24 | ServerName = svName;
25 | UseAKey = useAkey;
26 | Debug = debug;
27 | RateExp = exp;
28 | RateMoney = money;
29 | RateSp = sp;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/packages/mongocsharpdriver.1.9.0/mongocsharpdriver.1.9.0.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | mongocsharpdriver
5 | 1.9.0
6 | Official MongoDB C# driver
7 | MongoDB, Inc.
8 | MongoDB, Inc.
9 | http://www.apache.org/licenses/LICENSE-2.0
10 | http://www.mongodb.org/display/DOCS/CSharp+Language+Center
11 | http://jobs.mongodb.org/files/logos/889002/889002.png
12 | true
13 | Official C# driver for MongoDB
14 |
15 |
16 | en-US
17 | mongodb mongo nosql
18 |
19 |
--------------------------------------------------------------------------------
/GameServer/Model/Creature/Creature.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace GameServer.Model.Creature
8 | {
9 | public abstract class Creature : GameObject
10 | {
11 | private CreatureLifeStats _lifeStats;
12 |
13 | public CreatureLifeStats LifeStats
14 | {
15 | get { return _lifeStats ?? (_lifeStats = new CreatureLifeStats(this)); }
16 | }
17 |
18 | public CreatureBaseStats GameStats;
19 |
20 | public int MaxHp
21 | {
22 | get { return GameStats.HpBase; }
23 | }
24 |
25 | public int MaxMp
26 | {
27 | get { return GameStats.MpBase; }
28 | }
29 |
30 | public int MaxSp
31 | {
32 | get { return GameStats.SpBase; }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LoginServer/Network/Recv/RequestSelectServer.cs:
--------------------------------------------------------------------------------
1 | using LoginServer.Network.Send;
2 | using LoginServer.Service;
3 | using System.Linq;
4 |
5 | namespace LoginServer.Network.Recv
6 | {
7 | public class RequestSelectServer : ARecvPacket
8 | {
9 | protected int serverId;
10 | protected int channelId;
11 | protected internal override void Read()
12 | {
13 | serverId = ReadD();
14 | channelId = ReadD();
15 | ReadC();
16 | }
17 |
18 | protected internal override void Run()
19 | {
20 | var server = LoginServer.ServerList[serverId];
21 |
22 | if (server.IsUseAtKey && !_Client._Account.HasAKey)
23 | _Client.SendPacket(new ResponseLogin(AuthResponse.NoAtKey));
24 | else
25 | _Client.SendPacket(new ResponseSelectServer(serverId, channelId));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/LoginServer/Network/Recv/RequestLogin.cs:
--------------------------------------------------------------------------------
1 | using LoginServer.Network.GameServer;
2 | using LoginServer.Network.GameServer.Send;
3 | using LoginServer.Network.Send;
4 | using LoginServer.Service;
5 |
6 | namespace LoginServer.Network.Recv
7 | {
8 | public class RequestLogin : ARecvPacket
9 | {
10 | protected string Login;
11 | protected string MD5Pass;
12 |
13 | protected internal override void Read()
14 | {
15 | Login = ReadS();
16 | MD5Pass = ReadS();
17 | }
18 |
19 | protected internal override void Run()
20 | {
21 | var resp = AuthService.GetInstance().AuthAccount(Login, MD5Pass, ref _Client._Account);
22 |
23 | foreach (GSClient client in GameServerManager.GetInstance().GetAllGSClient())
24 | client.SendPacket(new LSReqUserOnlineCount());
25 |
26 | _Client.SendPacket(new ResponseLogin(resp));
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/Recv/GSResUserOnlineCount.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using LoginServer.Service;
3 | using ProtoBuf;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace LoginServer.Network.GameServer.Recv
12 | {
13 | public class GSResUserOnlineCount : GSARecvPacket
14 | {
15 | protected internal override void Read()
16 | {
17 | int serverId = ReadD();
18 | int count = ReadH();
19 | for(int i = 0; i < count; i++)
20 | {
21 | int channelId = ReadH();
22 | int online = ReadD();
23 |
24 | AuthService.GetInstance().UpdateChannelCurrentUserCount(serverId, channelId, online);
25 | }
26 | }
27 |
28 | protected internal override void Run()
29 | {
30 |
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/GameServer/Network/LoginServer/Send/GSResUserOnlineCount.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using Common.Utilities;
3 | using GameServer.Config;
4 | using ProtoBuf;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace GameServer.Network.LoginServer.Send
13 | {
14 | public class GSResUserOnlineCount : LSASendPacket
15 | {
16 | public GSResUserOnlineCount()
17 | {
18 |
19 | }
20 |
21 | protected internal override void Write()
22 | {
23 | WriteD(Configuration.Setting.ServerId);
24 | WriteH(Configuration.GetInstance().Channels.Count);
25 | foreach (ChannelStruct channel in Configuration.GetInstance().Channels)
26 | {
27 | int online = ClientManager.GetInstance().GetUserOnlineCount(channel.Id);
28 | WriteH(channel.Id);
29 | WriteD(online);
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestCreateCharacter.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Model.Character;
2 | using GameServer.Service;
3 |
4 | namespace GameServer.Network.Recv
5 | {
6 | public class RequestCreateCharacter : ARecvPacket
7 | {
8 | protected Character Character;
9 | protected internal override void Read()
10 | {
11 | Character = new Character();
12 | Character.Name = ReadS(15);
13 | ReadC();
14 | Character.Class = (CharacterClass)ReadC();
15 | Character.HairStyle = ReadC();
16 | Character.HairColor = ReadC();
17 | Character.Face = ReadC();
18 | Character.Voice = ReadC();
19 | ReadC(); // UNK
20 | Character.Gender = (CharacterGender)ReadC();
21 | ReadC(); // UNK
22 | ReadD(); // UNK
23 | }
24 |
25 | protected internal override void Run()
26 | {
27 | CharacterService.GetInstance().CreateCharacter(_Client._Account, Character);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/LoginServer/Network/Opcode.cs:
--------------------------------------------------------------------------------
1 | using LoginServer.Network.Recv;
2 | using LoginServer.Network.Send;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace LoginServer.Network
10 | {
11 | public class Opcode
12 | {
13 | public static Dictionary Recv = new Dictionary();
14 | public static Dictionary Send = new Dictionary();
15 |
16 | public static void Init()
17 | {
18 | Recv.Add(unchecked((short)0x8000), typeof(RequestLogin));
19 | Recv.Add(unchecked((short)0x8016), typeof(RequestServerList));
20 | Recv.Add(unchecked((short)0x800C), typeof(RequestSelectServer));
21 |
22 |
23 | Send.Add(typeof(ResponseLogin), unchecked((short)0x8001));
24 | Send.Add(typeof(ResponseServerList), unchecked((short)0x8017));
25 | Send.Add(typeof(ResponseSelectServer), unchecked((short)0x8064));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/packages/Trove.Nini.1.1.0.0/Trove.Nini.1.1.0.0.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Trove.Nini
5 | 1.1.0.0
6 | Trove Unofficial Nini Configuration
7 | Alan Dean
8 | Alan Dean
9 | http://nini.svn.sourceforge.net/viewvc/nini/trunk/Nini/LICENSE.txt?revision=242&view=markup
10 | http://nini.sourceforge.net/
11 | http://www.alan-dean.com/sourceforge.png
12 | true
13 | Nini is an uncommonly powerful .NET configuration library designed to help build highly configurable applications quickly.
14 | An unofficial package of the Nini Configuration library.
15 |
16 | Copyright © 2006 Brent R. Matzelle
17 |
18 | INI Configuration
19 |
20 |
--------------------------------------------------------------------------------
/packages/mongocsharpdriver.1.9.0/License.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033\deflangfe1033{\fonttbl{\f0\fmodern\fprq1\fcharset0 Courier New;}{\f1\fswiss\fprq2\fcharset0 Calibri;}}
2 | {\colortbl ;\red0\green0\blue255;}
3 | {\*\generator Riched20 6.2.9200}{\*\mmathPr\mnaryLim0\mdispDef1\mwrapIndent1440 }\viewkind4\uc1
4 | \pard\widctlpar\f0\fs20 Copyright 2010-2014 MongoDB Inc.\par
5 | \par
6 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\par
7 | \par
8 | {{\field{\*\fldinst{HYPERLINK http://www.apache.org/licenses/LICENSE-2.0 }}{\fldrslt{http://www.apache.org/licenses/LICENSE-2.0\ul0\cf0}}}}\f0\fs20\par
9 | \par
10 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\par
11 |
12 | \pard\widctlpar\sa200\sl276\slmult1\f1\fs22\par
13 | }
14 |
--------------------------------------------------------------------------------
/packages/NLog.2.1.0/NLog.2.1.0.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | NLog
5 | 2.1.0
6 | NLog
7 | Kim Christensen
8 | Kim Christensen
9 | http://raw.github.com/NLog/NLog/master/LICENSE.txt
10 | http://github.com/NLog/NLog/
11 | http://nlog-project.org/N.png
12 | false
13 | NLog is a logging platform for .NET with rich log routing and management capabilities. It can help you produce and manage high-quality logs for your application regardless of its size or complexity.
14 | This package installs NLog.dll with includes core logging functionality.
15 | For your main project also need to install "NLog Configuration" package.
16 | NLog - Advanced .NET and Silverlight Logging
17 |
18 |
19 | en-US
20 |
21 |
--------------------------------------------------------------------------------
/GameServer/Model/Item/Storage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace GameServer.Model.Item
8 | {
9 | public class Storage
10 | {
11 | public StorageType StorageType;
12 |
13 | public SortedDictionary Items = new SortedDictionary();
14 |
15 | public object ItemsLock = new object();
16 |
17 | public long Money = 100;
18 |
19 | public short Size = 36;
20 |
21 | public int MaxWeight = 500;
22 |
23 | public bool Locked = false;
24 |
25 | public Storage()
26 | {
27 | if (StorageType == Item.StorageType.Equipment)
28 | for (int i = 0; i < 15; i++)
29 | Items.Add(i, null);
30 | }
31 |
32 | public StorageItem GetItem(int slot)
33 | {
34 | lock (ItemsLock)
35 | {
36 | if (Items.ContainsKey(slot))
37 | return Items[slot];
38 | }
39 |
40 | return null;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/GameServer/Network/LoginServer/Send/GSReqRegistServer.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using GameServer.Config;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace GameServer.Network.LoginServer.Send
10 | {
11 | public class GSReqRegistServer : LSASendPacket
12 | {
13 | protected internal override void Write()
14 | {
15 | WriteD(Configuration.Setting.ServerId);
16 | WriteS(Configuration.Setting.ServerName);
17 | WriteS(Configuration.Network.PublicIp);
18 | WriteC((Configuration.Setting.UseAKey) ? 1 : 0);
19 | WriteD(Configuration.GetInstance().Channels.Count);
20 | foreach(ChannelStruct channel in Configuration.GetInstance().Channels)
21 | {
22 | WriteH(channel.Id);
23 | WriteS(channel.Name);
24 | WriteH(channel.Port);
25 | WriteC(channel.Type);
26 | WriteD(channel.MaxUser);
27 | WriteD(channel.CurrentUser);
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/LoginServer/Network/Send/ResponseServerList.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using Common.Utilities;
3 | using System.Linq;
4 |
5 | namespace LoginServer.Network.Send
6 | {
7 | public class ResponseServerList : ASendPacket
8 | {
9 | protected internal override void Write()
10 | {
11 | WriteH(LoginServer.ServerList.Count);
12 |
13 | foreach(ServerStruct server in LoginServer.ServerList.Values)
14 | {
15 | WriteH(server.Id);
16 | WriteS(server.Name);
17 | WriteH(0);
18 | WriteH(0);
19 | WriteH(1);
20 | WriteH(server.Channels.Count);
21 | foreach (var channel in server.Channels.Values.ToList())
22 | {
23 | int online = channel.CurrentUser; // todo get user online in channel
24 | int percent = ((online * 100) / channel.MaxUser);
25 | WriteH(channel.Id);
26 | WriteS(channel.Name);
27 | WriteH(percent);
28 | WriteH(channel.Type);
29 | }
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseAuth.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace GameServer.Network.Send
9 | {
10 | public class ResponseAuth : ASendPacket
11 | {
12 | protected internal override void Write()
13 | {
14 | WriteH(0);
15 | WriteH(0);
16 | WriteH(1); // gender
17 | WriteH(0);
18 |
19 | WriteH(0);
20 | WriteH(0);
21 | WriteH(9);
22 | WriteH(0);
23 | WriteH(0);
24 | WriteH(0);
25 | WriteH(0); //1
26 |
27 | WriteH(0);
28 | WriteH(14);
29 | WriteH(0);
30 | WriteH(1);
31 | WriteH(4369);
32 | WriteH(0);
33 | WriteH(4369);
34 | WriteH(0);
35 | WriteH(4369);
36 |
37 | WriteC(0xff);
38 | WriteC(0xff);
39 |
40 | WriteD(0);
41 | WriteD(Funcs.GetRoundedLocal());
42 | WriteD(28);
43 | WriteB(Funcs.NextBytes(4));
44 | WriteH(0x5041);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/LoginServer/Network/Send/ResponseLogin.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using LoginServer.Service;
3 |
4 | namespace LoginServer.Network.Send
5 | {
6 | public class ResponseLogin : ASendPacket
7 | {
8 | protected AuthResponse Response;
9 |
10 | public ResponseLogin(AuthResponse resp)
11 | {
12 | Response = resp;
13 | }
14 |
15 | protected internal override void Write()
16 | {
17 | switch(Response)
18 | {
19 | case AuthResponse.Success:
20 | WriteH(0);
21 | WriteH(0);
22 | WriteS(_Client._Account.Name);
23 | WriteC(0);
24 | WriteS(_Client._Account.Name);
25 | break;
26 | case AuthResponse.WrongInfo:
27 | WriteH(1);
28 | WriteH(3);
29 | break;
30 | case AuthResponse.NoAtKey:
31 | WriteD(36);
32 | break;
33 | case AuthResponse.Banned:
34 | Log.Error("Banned Response is not implement");
35 | break;
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/LoginServer/Network/ClientManager.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System.Collections.Generic;
3 | using System.Net.Sockets;
4 |
5 | namespace LoginServer.Network
6 | {
7 | internal class ClientManager
8 | {
9 | private static ClientManager Instance = new ClientManager();
10 | private List _Clients = new List();
11 |
12 | static ClientManager()
13 | {
14 | }
15 |
16 | public ClientManager()
17 | {
18 | Log.Info("ClientManager Loaded");
19 | }
20 |
21 | public static ClientManager GetInstance()
22 | {
23 | return ClientManager.Instance;
24 | }
25 |
26 | public void AddClient(TcpClient tcp)
27 | {
28 | // todo block ip
29 | string ip = tcp.Client.RemoteEndPoint.ToString().Split(':')[0];
30 |
31 |
32 | Client client = new Client(tcp);
33 | if (_Clients.Contains(client))
34 | Log.Warn("Client is already exists!");
35 | else
36 | _Clients.Add(client);
37 | }
38 |
39 | public void RemoveClient(Client loginClient)
40 | {
41 | if (!this._Clients.Contains(loginClient))
42 | return;
43 |
44 | this._Clients.Remove(loginClient);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/Recv/GSResRegistServer.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using Common.Utilities;
3 |
4 | namespace LoginServer.Network.GameServer.Recv
5 | {
6 | public class GSResRegistServer : GSARecvPacket
7 | {
8 | protected int serverId;
9 | protected internal override void Read()
10 | {
11 | serverId = ReadD();
12 | string serverName = ReadS();
13 | string serverAddr = ReadS();
14 | bool useAkey = (ReadC() == 1) ? true : false;
15 | ServerStruct server = new ServerStruct(serverId, serverName, serverAddr, useAkey);
16 |
17 | int channel_count = ReadD();
18 | for(int i = 0; i < channel_count; i++)
19 | {
20 | int id = ReadH();
21 | string name = ReadS();
22 | int port = ReadH();
23 | int type = ReadC();
24 | int max = ReadD();
25 | int curr = ReadD();
26 | ChannelStruct channel = new ChannelStruct(id, name, port, type, max, curr);
27 | server.Channels.Add(channel.Id, channel);
28 | }
29 |
30 | LoginServer.ServerList.Add(server.Id, server);
31 | }
32 |
33 | protected internal override void Run()
34 | {
35 | Log.Info("Registered Server ID: {0}", serverId);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/GameServer/Network/Recv/RequestAuth.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Database;
2 | using GameServer.Model.Account;
3 | using GameServer.Network.Send;
4 | using GameServer.Service;
5 | using System.Text;
6 |
7 | namespace GameServer.Network.Recv
8 | {
9 | public class RequestAuth : ARecvPacket
10 | {
11 | protected string Name;
12 | protected string Md5Pass;
13 | protected int chnId;
14 | protected string IpAddress;
15 |
16 | protected internal override void Read()
17 | {
18 | Name = Encoding.Default.GetString(ReadB(31)).Replace("\0", "");
19 | Md5Pass = Encoding.Default.GetString(ReadB(31));
20 | ReadH();
21 | ReadH();
22 | chnId = ReadH();
23 | IpAddress = Encoding.Default.GetString(ReadB(15)).Replace("\0", "");
24 | }
25 |
26 | protected internal override void Run()
27 | {
28 | _Client._Account = AuthService.GetInstance().AuthAccount(Name, Md5Pass);
29 | if (_Client._Account != null)
30 | {
31 | _Client._Account._Client = _Client;
32 | _Client._Account.LastAddress = IpAddress;
33 | _Client._Account.Setting = new AccountSetting();
34 | MdbAccount.GetInstance().UpdateAccount(_Client._Account);
35 | _Client.SendPacket(new ResponseAuth());
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Common/NLog.config:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Common/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Common")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Common")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("284cc8d3-43b6-416a-b8ef-bd96813dd7fd")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GameServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("GameServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("GameServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("3131cb08-f62f-45dc-b601-ba8b76ed8654")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/LoginServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("LoginServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("LoginServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1ce0e582-d074-476b-b7ff-abacc2021a19")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/LoginServer/LoginServer.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using LoginServer.Config;
3 | using LoginServer.Network;
4 | using LoginServer.Network.GameServer;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Diagnostics;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 |
13 | namespace LoginServer
14 | {
15 | internal class LoginServer
16 | {
17 | public static Dictionary ServerList = new Dictionary();
18 |
19 | static void Main(string[] args)
20 | {
21 | Console.Title = "YGCore LoginServer";
22 | Console.WriteLine("Authors: Jenose\n"
23 | + "Authorized representative: netgame.in.th\n\n"
24 | + "-------------------------------------------\n");
25 |
26 | Stopwatch sw = Stopwatch.StartNew();
27 |
28 | Configuration.GetInstance();
29 |
30 | ClientManager.GetInstance();
31 | GameServerManager.GetInstance();
32 | GSNetworkFactory.GetInstance();
33 | NetworkFactory.GetInstance();
34 |
35 | sw.Stop();
36 |
37 | Thread.Sleep(100);
38 | Console.WriteLine("-------------------------------------------");
39 | Console.WriteLine(" Server start in {0}", (sw.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
40 | Console.WriteLine("-------------------------------------------");
41 |
42 | Process.GetCurrentProcess().WaitForExit();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/GameServerManager.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Net.Sockets;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace LoginServer.Network.GameServer
10 | {
11 | internal class GameServerManager
12 | {
13 | private static GameServerManager Instance = new GameServerManager();
14 | private List _Clients = new List();
15 |
16 | static GameServerManager()
17 | {
18 | }
19 |
20 | public GameServerManager()
21 | {
22 | Log.Info("GameServerManager Loaded");
23 | }
24 |
25 | public static GameServerManager GetInstance()
26 | {
27 | return GameServerManager.Instance;
28 | }
29 |
30 | public void AddClient(TcpClient tcp)
31 | {
32 | // todo block ip
33 | string ip = tcp.Client.RemoteEndPoint.ToString().Split(':')[0];
34 |
35 |
36 | GSClient client = new GSClient(tcp);
37 | if (_Clients.Contains(client))
38 | Log.Warn("Client is already exists!");
39 | else
40 | _Clients.Add(client);
41 | }
42 |
43 | public void RemoveClient(GSClient loginClient)
44 | {
45 | if (!this._Clients.Contains(loginClient))
46 | return;
47 |
48 | this._Clients.Remove(loginClient);
49 | }
50 |
51 | public List GetAllGSClient()
52 | {
53 | return _Clients;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/GameServer/GameServer.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Config;
2 | using GameServer.DataHolder;
3 | using GameServer.Network;
4 | using GameServer.Network.LoginServer;
5 | using GameServer.Service;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Diagnostics;
9 | using System.Linq;
10 | using System.Text;
11 | using System.Threading;
12 | using System.Threading.Tasks;
13 |
14 | namespace GameServer
15 | {
16 | class GameServer
17 | {
18 | static void Main(string[] args)
19 | {
20 | Console.Title = "YGCore GameServer";
21 | Console.WriteLine("Authors: Jenose\n"
22 | + "Authorized representative: netgame.in.th\n\n"
23 | + "-------------------------------------------\n");
24 |
25 | Stopwatch sw = Stopwatch.StartNew();
26 |
27 | Opcode.Init();
28 | Configuration.GetInstance();
29 | Data.LoadAll();
30 |
31 | StatsService.GetInstance();
32 |
33 | ClientManager.GetInstance();
34 | LSClient.GetInstance();
35 |
36 | foreach(var channel in Configuration.GetInstance().Channels)
37 | NetworkFactory.NewInstance(channel.Port);
38 |
39 | sw.Stop();
40 |
41 | Thread.Sleep(100);
42 | Console.WriteLine("-------------------------------------------");
43 | Console.WriteLine(" Server start in {0}", (sw.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
44 | Console.WriteLine("-------------------------------------------");
45 |
46 | Process.GetCurrentProcess().WaitForExit();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/LoginServer/Database/MdbAccount.cs:
--------------------------------------------------------------------------------
1 | using LoginServer.Config;
2 | using LoginServer.Model.Account;
3 | using MongoDB.Driver;
4 | using MongoDB.Driver.Builders;
5 |
6 | namespace LoginServer.Database
7 | {
8 | public class MdbAccount
9 | {
10 | private static MdbAccount Instance;
11 |
12 | public static MdbAccount GetInstance()
13 | {
14 | return (Instance != null) ? Instance : Instance = new MdbAccount();
15 | }
16 |
17 | private MongoClient m_Client;
18 | private MongoServer m_Server;
19 | private MongoDatabase m_Database;
20 | private MongoCollection m_Collection;
21 |
22 | private string MDBAccountTable = "accounts";
23 |
24 | public MdbAccount()
25 | {
26 | m_Client = new MongoClient(Configuration.Database.Url);
27 | m_Server = m_Client.GetServer();
28 | m_Database = m_Server.GetDatabase(Configuration.Database.Name);
29 | m_Collection = m_Database.GetCollection(MDBAccountTable);
30 | }
31 |
32 | public Account GetAccountByName(string name)
33 | {
34 | var query = Query.EQ(a => a.Name, name);
35 | var account = m_Collection.FindOne(query);
36 | return (account != null) ? account : null;
37 | }
38 |
39 | public void AddAccount(Account acc)
40 | {
41 | m_Collection.Insert(acc);
42 | }
43 |
44 | public void UpdateAccount(Account acc)
45 | {
46 | var query = Query.EQ(e => e.Id, acc.Id);
47 | var update = Update
48 | .Set(e => e.LastAddress, acc.LastAddress);
49 | m_Collection.Update(query, update);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/GameServer/Database/MdbAccount.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Config;
2 | using GameServer.Model.Account;
3 | using GameServer.Model.Character;
4 | using MongoDB.Driver;
5 | using MongoDB.Driver.Builders;
6 |
7 | namespace GameServer.Database
8 | {
9 | public class MdbAccount
10 | {
11 | private static MdbAccount Instance;
12 |
13 | public static MdbAccount GetInstance()
14 | {
15 | return (Instance != null) ? Instance : Instance = new MdbAccount();
16 | }
17 |
18 | private MongoClient m_Client;
19 | private MongoServer m_Server;
20 | private MongoDatabase m_Database;
21 | private MongoCollection m_Collection;
22 |
23 | private string MDBTable = "accounts";
24 |
25 | public MdbAccount()
26 | {
27 | m_Client = new MongoClient(Configuration.Database.Url);
28 | m_Server = m_Client.GetServer();
29 | m_Database = m_Server.GetDatabase(Configuration.Database.Name);
30 | m_Collection = m_Database.GetCollection(MDBTable);
31 | }
32 |
33 | public Account GetAccountByName(string name)
34 | {
35 | var query = Query.EQ(a => a.Name, name);
36 | var account = m_Collection.FindOne(query);
37 | return (account != null) ? account : null;
38 | }
39 |
40 | public void AddAccount(Account acc)
41 | {
42 | m_Collection.Insert(acc);
43 | }
44 |
45 | public void UpdateAccount(Account acc)
46 | {
47 | var query = Query.EQ(e => e.Id, acc.Id);
48 | var update = Update
49 | .Set(e => e.LastAddress, acc.LastAddress);
50 | m_Collection.Update(query, update);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/GameServer/Model/Account/AccountSetting.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace GameServer.Model.Account
5 | {
6 | public class AccountSetting
7 | {
8 | public int PartyFriend { get; set; }
9 |
10 | public int PartySearch { get; set; }
11 |
12 | public int CanTrade { get; set; }
13 |
14 | public int CanWhisper { get; set; }
15 |
16 | public int CostumeType { get; set; }
17 |
18 | public int HairSwitch { get; set; }
19 |
20 | public int WeaponSwitch { get; set; }
21 |
22 | public int PetExp { get; set; }
23 |
24 | public int FameSwitch { get; set; }
25 |
26 | [MethodImpl(MethodImplOptions.NoInlining)]
27 | public static int GetSettings(AccountSetting Setting)
28 | {
29 | int flags = 0;
30 | if (Setting.HairSwitch == 1)
31 | {
32 | SetFlags(ref flags, 7, true);
33 | }
34 | if (Setting.CostumeType == 1)
35 | {
36 | SetFlags(ref flags, 4, true);
37 | return flags;
38 | }
39 | SetFlags(ref flags, 6, true);
40 | return flags;
41 | }
42 |
43 | [MethodImpl(MethodImplOptions.NoInlining)]
44 | public static void SetFlags(ref int Flags, int ItemFlag, bool value)
45 | {
46 | int[] values = new int[] { Flags };
47 | BitArray array = new BitArray(values);
48 | array.Set(ItemFlag, value);
49 | Flags = 0;
50 | for (int i = 0; i < array.Length; i++)
51 | {
52 | if (array.Get(i))
53 | {
54 | Flags |= ((int)1) << i;
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/LoginServer/Network/NetworkFactory.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using LoginServer.Config;
3 | using System;
4 | using System.Net;
5 | using System.Net.Sockets;
6 | using System.Threading;
7 |
8 | namespace LoginServer.Network
9 | {
10 | internal class NetworkFactory
11 | {
12 | private static NetworkFactory Instance;
13 |
14 | private static TcpListener NetworkListener;
15 |
16 | public NetworkFactory()
17 | {
18 | new Thread(new ThreadStart(NetworkStart)).Start();
19 | }
20 |
21 | public static NetworkFactory GetInstance()
22 | {
23 | return (Instance != null) ? Instance : Instance = Instance = new NetworkFactory();
24 | }
25 |
26 | private void NetworkStart()
27 | {
28 | try
29 | {
30 | Opcode.Init();
31 | NetworkListener = new TcpListener(IPAddress.Parse(Configuration.Network.PublicIp), Configuration.Network.PublicPort);
32 | NetworkListener.Start();
33 | Log.Info("Server listening clients at {0}:{1}...", ((IPEndPoint)NetworkListener.LocalEndpoint).Address, Configuration.Network.PublicPort);
34 | NetworkListener.BeginAcceptTcpClient(new AsyncCallback(BeginAcceptTcpClient), (object)null);
35 | }
36 | catch (Exception ex)
37 | {
38 | Log.ErrorException("NetworkStart:", ex);
39 | }
40 | }
41 |
42 | private void BeginAcceptTcpClient(IAsyncResult ar)
43 | {
44 | Accept(NetworkListener.EndAcceptTcpClient(ar));
45 | NetworkListener.BeginAcceptTcpClient(new AsyncCallback(this.BeginAcceptTcpClient), (object)null);
46 | }
47 |
48 | private void Accept(TcpClient tcpClient)
49 | {
50 | ClientManager.GetInstance().AddClient(tcpClient);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/GameServer/Network/NetworkFactory.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using GameServer.Config;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Net;
7 | using System.Net.Sockets;
8 | using System.Text;
9 | using System.Threading;
10 | using System.Threading.Tasks;
11 |
12 | namespace GameServer.Network
13 | {
14 | internal class NetworkFactory
15 | {
16 | private static List Instances = new List();
17 |
18 | private TcpListener NetworkListener;
19 |
20 | public NetworkFactory(int port)
21 | {
22 | new Thread(new ParameterizedThreadStart(NetworkStart)).Start(port);
23 | }
24 |
25 | public static void NewInstance(int port)
26 | {
27 | Instances.Add(new NetworkFactory(port));
28 | }
29 |
30 | private void NetworkStart(object parameter)
31 | {
32 | try
33 | {
34 | int port = (int)parameter;
35 | NetworkListener = new TcpListener(IPAddress.Parse(Configuration.Network.PublicIp), port);
36 | NetworkListener.Start();
37 | Log.Info("Server listening clients at {0}:{1}...", ((IPEndPoint)NetworkListener.LocalEndpoint).Address, port);
38 | NetworkListener.BeginAcceptTcpClient(new AsyncCallback(BeginAcceptTcpClient), (object)null);
39 | }
40 | catch (Exception ex)
41 | {
42 | Log.ErrorException("NetworkStart:", ex);
43 | }
44 | }
45 |
46 | private void BeginAcceptTcpClient(IAsyncResult ar)
47 | {
48 | Accept(NetworkListener.EndAcceptTcpClient(ar));
49 | NetworkListener.BeginAcceptTcpClient(new AsyncCallback(this.BeginAcceptTcpClient), (object)null);
50 | }
51 |
52 | private void Accept(TcpClient tcpClient)
53 | {
54 | ClientManager.GetInstance().AddClient(tcpClient);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/YGCore.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoginServer", "LoginServer\LoginServer.csproj", "{D2C7CE20-856E-4524-B246-B17BE603BB49}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{2CC06D57-6A68-473D-A7ED-D19CA8381B57}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameServer", "GameServer\GameServer.csproj", "{05AD4BBF-5D1F-4AD7-878E-A634732D29AC}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {D2C7CE20-856E-4524-B246-B17BE603BB49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {D2C7CE20-856E-4524-B246-B17BE603BB49}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {D2C7CE20-856E-4524-B246-B17BE603BB49}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {D2C7CE20-856E-4524-B246-B17BE603BB49}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {2CC06D57-6A68-473D-A7ED-D19CA8381B57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {2CC06D57-6A68-473D-A7ED-D19CA8381B57}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {2CC06D57-6A68-473D-A7ED-D19CA8381B57}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {2CC06D57-6A68-473D-A7ED-D19CA8381B57}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {05AD4BBF-5D1F-4AD7-878E-A634732D29AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {05AD4BBF-5D1F-4AD7-878E-A634732D29AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {05AD4BBF-5D1F-4AD7-878E-A634732D29AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {05AD4BBF-5D1F-4AD7-878E-A634732D29AC}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/LoginServer/Config/Configuration.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using Nini.Config;
3 | using System;
4 |
5 | namespace LoginServer.Config
6 | {
7 | public class Configuration
8 | {
9 | private static Configuration Instance;
10 |
11 | private static IConfig _DBCfg = new IniConfigSource("Config/database.ini").Configs["database"];
12 | private static IConfig _NWCfg = new IniConfigSource("Config/network.ini").Configs["network"];
13 | private static IConfig _STCfg = new IniConfigSource("Config/setting.ini").Configs["setting"];
14 |
15 | public static DatabaseStruct Database;
16 | public static NetworkStruct Network;
17 | public static SettingStruct Setting;
18 |
19 | public Configuration()
20 | {
21 | Console.WriteLine("Load All Configuration...");
22 | Console.WriteLine("-------------------------------------------");
23 | Database = new DatabaseStruct(
24 | _DBCfg.GetString("db.mongo.url"),
25 | _DBCfg.GetString("db.mongo.name")
26 | );
27 | Log.Info("Loaded Database Configuration");
28 | Network = new NetworkStruct(
29 | _NWCfg.GetString("public.ip"),
30 | _NWCfg.GetInt("public.port"),
31 | _NWCfg.GetString("private.ip"),
32 | _NWCfg.GetInt("private.port")
33 | );
34 | Log.Info("Loaded Network Configuration");
35 | Setting = new SettingStruct(
36 | _STCfg.GetBoolean("debuging"),
37 | _STCfg.GetBoolean("autoaccount"),
38 | _STCfg.GetBoolean("gmonly")
39 | );
40 | Log.Info("Loaded Setting Configuration");
41 | Console.WriteLine("\n-------------------------------------------\n");
42 | }
43 |
44 | public static Configuration GetInstance()
45 | {
46 | return (Instance != null) ? Instance : Instance = Instance = new Configuration();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/GameServer/Network/Opcode.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Network.Recv;
2 | using GameServer.Network.Send;
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace GameServer.Network
7 | {
8 | public class Opcode
9 | {
10 | public static Dictionary Recv = new Dictionary();
11 | public static Dictionary Send = new Dictionary();
12 |
13 | public static void Init()
14 | {
15 | Recv.Add(unchecked((short)0x0001), typeof(RequestAuth));
16 | Recv.Add(unchecked((short)0x0003), typeof(RequestExit));
17 | Recv.Add(unchecked((short)0x0005), typeof(RequestEntergame));
18 | Recv.Add(unchecked((short)0x0010), typeof(RequestCharacterList));
19 | Recv.Add(unchecked((short)0x0014), typeof(RequestCreateCharacter));
20 | Recv.Add(unchecked((short)0x001E), typeof(RequestDeleteCharacter));
21 | Recv.Add(unchecked((short)0x0038), typeof(RequestCheckName));
22 | Recv.Add(unchecked((short)0x003C), typeof(RequestUseSkill));
23 | Recv.Add(unchecked((short)0x008F), typeof(RequestInitGame));
24 |
25 |
26 | Send.Add(typeof(ResponseAuth), unchecked((short)0x0002));
27 | Send.Add(typeof(ResponseExit), unchecked((short)0x0004));
28 | Send.Add(typeof(ResponseRunning), unchecked((short)0x0006));
29 | Send.Add(typeof(ResponseCharacterList), unchecked((short)0x0011));
30 | Send.Add(typeof(ResponseCreateCharacter), unchecked((short)0x0015));
31 | Send.Add(typeof(ResponseDeleteCharacter), unchecked((short)0x001F));
32 | Send.Add(typeof(ResponseInitGame), unchecked((short)0x0020));
33 | Send.Add(typeof(ResponseCheckName), unchecked((short)0x0039));
34 | Send.Add(typeof(ResponseSetBuff), unchecked((short)0x003D));
35 | Send.Add(typeof(ResponseCharacterInfo), unchecked((short)0x0064));
36 | Send.Add(typeof(ResponseServerTime), unchecked((short)0x0080));
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Common/Utilities/IDFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Threading;
4 |
5 | namespace Common.Utilities
6 | {
7 | public class IDFactory
8 | {
9 | private List Ids = new List();
10 |
11 | private long lastId = 0;
12 |
13 | public IDFactory(long lid)
14 | {
15 | lastId = lid;
16 | Ids.Add(lastId);
17 | }
18 |
19 | public long Register(long uid)
20 | {
21 | lock (Ids)
22 | {
23 | lastId = uid;
24 |
25 | while (!Ids.Contains(lastId))
26 | {
27 | if (Ids.Contains(lastId))
28 | {
29 | Interlocked.Increment(ref lastId);
30 | }
31 | else
32 | {
33 | Ids.Add(lastId);
34 | break;
35 | }
36 | }
37 | }
38 |
39 | return lastId;
40 | }
41 |
42 | public long GetNext()
43 | {
44 | lock (Ids)
45 | {
46 | Interlocked.Increment(ref lastId);
47 |
48 | while (!Ids.Contains(lastId))
49 | {
50 | if (Ids.Contains(lastId))
51 | {
52 | Interlocked.Increment(ref lastId);
53 | }
54 | else
55 | {
56 | Ids.Add(lastId);
57 | break;
58 | }
59 | }
60 | }
61 |
62 | return lastId;
63 | }
64 |
65 | public void Release(long val)
66 | {
67 | lock (Ids)
68 | {
69 | if (Ids.Contains(val))
70 | {
71 | Ids.Remove(val);
72 | lastId = val;
73 | }
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/GSNetworkFactory.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using LoginServer.Config;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Net;
7 | using System.Net.Sockets;
8 | using System.Text;
9 | using System.Threading;
10 | using System.Threading.Tasks;
11 |
12 | namespace LoginServer.Network.GameServer
13 | {
14 | internal class GSNetworkFactory
15 | {
16 | private static GSNetworkFactory Instance;
17 |
18 | private static TcpListener NetworkListener;
19 |
20 | public GSNetworkFactory()
21 | {
22 | new Thread(new ThreadStart(NetworkStart)).Start();
23 | }
24 |
25 | public static GSNetworkFactory GetInstance()
26 | {
27 | return (Instance != null) ? Instance : Instance = Instance = new GSNetworkFactory();
28 | }
29 |
30 | private void NetworkStart()
31 | {
32 | try
33 | {
34 | GSOpcode.Init();
35 | NetworkListener = new TcpListener(IPAddress.Parse(Configuration.Network.PrivateIp), Configuration.Network.PrivatePort);
36 | NetworkListener.Start();
37 | Log.Info("Server listening gs clients at {0}:{1}...", ((IPEndPoint)NetworkListener.LocalEndpoint).Address, Configuration.Network.PrivatePort);
38 | NetworkListener.BeginAcceptTcpClient(new AsyncCallback(BeginAcceptTcpClient), (object)null);
39 | }
40 | catch (Exception ex)
41 | {
42 | Log.ErrorException("GS NetworkStart:", ex);
43 | }
44 | }
45 |
46 | private void BeginAcceptTcpClient(IAsyncResult ar)
47 | {
48 | Accept(NetworkListener.EndAcceptTcpClient(ar));
49 | NetworkListener.BeginAcceptTcpClient(new AsyncCallback(this.BeginAcceptTcpClient), (object)null);
50 | }
51 |
52 | private void Accept(TcpClient tcpClient)
53 | {
54 | GameServerManager.GetInstance().AddClient(tcpClient);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/GameServer/Model/Character/Character.cs:
--------------------------------------------------------------------------------
1 |
2 | using GameServer.Model.Item;
3 | using GameServer.Model.Map;
4 | namespace GameServer.Model.Character
5 | {
6 | public class Character : Creature.Creature
7 | {
8 | public string AccountName { get; set; }
9 |
10 | public int ServerId { get; set; }
11 |
12 | public string Name { get; set; }
13 |
14 | #region Info
15 | // ----- Info ----- //
16 |
17 | public CharacterGender Gender { get; set; }
18 |
19 | public CharacterClass Class { get; set; }
20 |
21 | public int Level { get; set; }
22 |
23 | public int JobLevel { get; set; }
24 |
25 | public long Exp { get; set; }
26 |
27 | public int SkillPoint { get; set; }
28 |
29 | public int AbilityPoint { get; set; }
30 |
31 | public int AscensionPoint { get; set; }
32 |
33 | public int CurrentAscensionPoint { get; set; }
34 |
35 | public int HonorPoint { get; set; }
36 |
37 | public int KarmaPoint { get; set; }
38 |
39 | public int DPoint { get; set; }
40 |
41 | public int CraftType { get; set; }
42 |
43 | public int CraftLevel { get; set; }
44 |
45 | public int CraftExp { get; set; }
46 |
47 | // ----- Info ----- //
48 | #endregion
49 |
50 | #region Appearance
51 | // ----- Appearance ----- //
52 |
53 | public int Title { get; set; }
54 |
55 | public int Forces { get; set; }
56 |
57 | public int HairStyle { get; set; }
58 |
59 | public int HairColor { get; set; }
60 |
61 | public int Face{ get; set; }
62 |
63 | public int Voice { get; set; }
64 |
65 | public byte[] NameStyle { get; set; }
66 |
67 | // ----- Appearance ----- //
68 | #endregion
69 |
70 | public MapPosition Position { get; set; }
71 |
72 | public Storage Inventory = new Storage { StorageType = StorageType.Inventory };
73 |
74 | public Storage Equipment = new Storage { StorageType = StorageType.Equipment };
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/LoginServer/Service/AuthService.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using LoginServer.Config;
3 | using LoginServer.Database;
4 | using LoginServer.Model.Account;
5 | using System.Linq;
6 |
7 | namespace LoginServer.Service
8 | {
9 | public enum AuthResponse
10 | {
11 | Success,
12 | WrongInfo,
13 | Banned,
14 | NoAtKey,
15 | }
16 |
17 | public class AuthService
18 | {
19 | private static AuthService Instance;
20 |
21 | public static AuthService GetInstance()
22 | {
23 | return (Instance != null) ? Instance : Instance = new AuthService();
24 | }
25 |
26 | public AuthResponse AuthAccount(string login, string password, ref Account account)
27 | {
28 | AuthResponse result;
29 |
30 | account = MdbAccount.GetInstance().GetAccountByName(login);
31 |
32 | if (account != null)
33 | {
34 | if (account.Password == password)
35 | result = AuthResponse.Success;
36 | else
37 | result = AuthResponse.WrongInfo;
38 | }
39 | else
40 | {
41 | if (Configuration.Setting.AutoAccount)
42 | {
43 | account = new Account()
44 | {
45 | Name = login,
46 | Password = password,
47 | LastAddress = "0.0.0.0",
48 | DeletePasswd = "0000000000",
49 | };
50 | MdbAccount.GetInstance().AddAccount(account);
51 | result = AuthResponse.Success;
52 | }
53 | else
54 | result = AuthResponse.WrongInfo;
55 | }
56 |
57 | return result;
58 | }
59 |
60 | public void UpdateChannelCurrentUserCount(int srvId, int chnId, int count)
61 | {
62 | var channel = LoginServer.ServerList[srvId].Channels[chnId];
63 | channel.CurrentUser = count;
64 | LoginServer.ServerList[srvId].Channels[chnId] = channel;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Common/Utilities/Log.cs:
--------------------------------------------------------------------------------
1 | using NLog;
2 | using System;
3 |
4 | namespace Common.Utilities
5 | {
6 | public abstract class Log
7 | {
8 | private static readonly Logger Logger = LogManager.GetLogger("Logger");
9 |
10 | //Trace 0
11 |
12 | public static void Trace(string format, params object[] args)
13 | {
14 | Logger.Trace(format, args);
15 | }
16 |
17 | public static void TraceException(string message, Exception ex)
18 | {
19 | Logger.TraceException(message, ex);
20 | }
21 |
22 | //Debug 1
23 |
24 | public static void Debug(string format, params object[] args)
25 | {
26 | Logger.Debug(format, args);
27 | }
28 |
29 | public static void DebugException(string message, Exception ex)
30 | {
31 | Logger.DebugException(message, ex);
32 | }
33 |
34 | //Info 2
35 |
36 | public static void Info(string format, params object[] args)
37 | {
38 | Logger.Info(format, args);
39 | }
40 |
41 | public static void InfoException(string message, Exception ex)
42 | {
43 | Logger.InfoException(message, ex);
44 | }
45 |
46 | //Warn 3
47 |
48 | public static void Warn(string format, params object[] args)
49 | {
50 | Logger.Warn(format, args);
51 | }
52 |
53 | public static void WarnException(string message, Exception ex)
54 | {
55 | Logger.WarnException(message, ex);
56 | }
57 |
58 | //Error 4
59 |
60 | public static void Error(string format, params object[] args)
61 | {
62 | Logger.Error(format, args);
63 | }
64 |
65 | public static void ErrorException(string message, Exception ex)
66 | {
67 | Logger.ErrorException(message, ex);
68 | }
69 |
70 | //Fatal 5
71 |
72 | public static void Fatal(string format, params object[] args)
73 | {
74 | Logger.Fatal(format, args);
75 | }
76 |
77 | public static void FatalException(string message, Exception ex)
78 | {
79 | Logger.FatalException(message, ex);
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/LoginServer/Network/ASendPacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace LoginServer.Network
6 | {
7 | public abstract class ASendPacket
8 | {
9 | private MemoryStream mstream = new MemoryStream();
10 |
11 | public Client _Client;
12 |
13 | public long Length
14 | {
15 | get
16 | {
17 | return this.mstream.Length;
18 | }
19 | }
20 |
21 | protected internal void WriteB(byte[] value)
22 | {
23 | this.mstream.Write(value, 0, value.Length);
24 | }
25 |
26 | protected internal void WriteD(int value)
27 | {
28 | WriteB(BitConverter.GetBytes(value));
29 | }
30 |
31 | protected internal void WriteH(short val)
32 | {
33 | WriteB(BitConverter.GetBytes(val));
34 | }
35 |
36 | protected internal void WriteH(int val)
37 | {
38 | WriteB(BitConverter.GetBytes((short)val));
39 | }
40 |
41 | protected internal void WriteC(byte value)
42 | {
43 | this.mstream.WriteByte(value);
44 | }
45 |
46 | protected internal void WriteC(int value)
47 | {
48 | this.mstream.WriteByte((byte)value);
49 | }
50 |
51 | protected internal void WriteF(double value)
52 | {
53 | WriteB(BitConverter.GetBytes(value));
54 | }
55 |
56 | protected internal void WriteQ(long value)
57 | {
58 | WriteB(BitConverter.GetBytes(value));
59 | }
60 |
61 | protected internal void WriteS(string value)
62 | {
63 | if (value == null)
64 | return;
65 |
66 | WriteH((short)value.Length);
67 | WriteB(Encoding.Default.GetBytes(value));
68 | }
69 |
70 | protected internal void WriteS(string name, int count)
71 | {
72 | if (name == null)
73 | return;
74 | WriteB(Encoding.Default.GetBytes(name));
75 | WriteB(new byte[count - name.Length]);
76 | }
77 |
78 | public byte[] ToByteArray()
79 | {
80 | return this.mstream.ToArray();
81 | }
82 |
83 | protected internal abstract void Write();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/GSASendPacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace LoginServer.Network.GameServer
6 | {
7 | public abstract class GSASendPacket
8 | {
9 | private MemoryStream mstream = new MemoryStream();
10 |
11 | public GSClient _Client;
12 |
13 | public long Length
14 | {
15 | get
16 | {
17 | return this.mstream.Length;
18 | }
19 | }
20 |
21 | protected internal void WriteB(byte[] value)
22 | {
23 | this.mstream.Write(value, 0, value.Length);
24 | }
25 |
26 | protected internal void WriteD(int value)
27 | {
28 | WriteB(BitConverter.GetBytes(value));
29 | }
30 |
31 | protected internal void WriteH(short val)
32 | {
33 | WriteB(BitConverter.GetBytes(val));
34 | }
35 |
36 | protected internal void WriteH(int val)
37 | {
38 | WriteB(BitConverter.GetBytes((short)val));
39 | }
40 |
41 | protected internal void WriteC(byte value)
42 | {
43 | this.mstream.WriteByte(value);
44 | }
45 |
46 | protected internal void WriteC(int value)
47 | {
48 | this.mstream.WriteByte((byte)value);
49 | }
50 |
51 | protected internal void WriteF(double value)
52 | {
53 | WriteB(BitConverter.GetBytes(value));
54 | }
55 |
56 | protected internal void WriteQ(long value)
57 | {
58 | WriteB(BitConverter.GetBytes(value));
59 | }
60 |
61 | protected internal void WriteS(string value)
62 | {
63 | if (value == null)
64 | return;
65 |
66 | WriteH((short)value.Length);
67 | WriteB(Encoding.Default.GetBytes(value));
68 | }
69 |
70 | protected internal void WriteS(string name, int count)
71 | {
72 | if (name == null)
73 | return;
74 | WriteB(Encoding.Default.GetBytes(name));
75 | WriteB(new byte[count - name.Length]);
76 | }
77 |
78 | public byte[] ToByteArray()
79 | {
80 | return this.mstream.ToArray();
81 | }
82 |
83 | protected internal abstract void Write();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/GameServer/Network/LoginServer/LSASendPacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace GameServer.Network.LoginServer
6 | {
7 | public abstract class LSASendPacket
8 | {
9 | private MemoryStream mstream = new MemoryStream();
10 |
11 | public LSClient _Client;
12 |
13 | public long Length
14 | {
15 | get
16 | {
17 | return this.mstream.Length;
18 | }
19 | }
20 |
21 | protected internal void WriteB(byte[] value)
22 | {
23 | this.mstream.Write(value, 0, value.Length);
24 | }
25 |
26 | protected internal void WriteD(int value)
27 | {
28 | WriteB(BitConverter.GetBytes(value));
29 | }
30 |
31 | protected internal void WriteH(short val)
32 | {
33 | WriteB(BitConverter.GetBytes(val));
34 | }
35 |
36 | protected internal void WriteH(int val)
37 | {
38 | WriteB(BitConverter.GetBytes((short)val));
39 | }
40 |
41 | protected internal void WriteC(byte value)
42 | {
43 | this.mstream.WriteByte(value);
44 | }
45 |
46 | protected internal void WriteC(int value)
47 | {
48 | this.mstream.WriteByte((byte)value);
49 | }
50 |
51 | protected internal void WriteF(double value)
52 | {
53 | WriteB(BitConverter.GetBytes(value));
54 | }
55 |
56 | protected internal void WriteQ(long value)
57 | {
58 | WriteB(BitConverter.GetBytes(value));
59 | }
60 |
61 | protected internal void WriteS(string value)
62 | {
63 | if (value == null)
64 | return;
65 |
66 | WriteH((short)value.Length);
67 | WriteB(Encoding.Default.GetBytes(value));
68 | }
69 |
70 | protected internal void WriteS(string name, int count)
71 | {
72 | if (name == null)
73 | return;
74 |
75 | WriteB(Encoding.Default.GetBytes(name));
76 | WriteB(new byte[count - name.Length]);
77 | }
78 |
79 | public byte[] ToByteArray()
80 | {
81 | return this.mstream.ToArray();
82 | }
83 |
84 | protected internal abstract void Write();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/GameServer/Database/MdbCharacter.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Config;
2 | using GameServer.Model.Character;
3 | using MongoDB.Driver;
4 | using MongoDB.Driver.Builders;
5 | using System.Collections.Generic;
6 |
7 | namespace GameServer.Database
8 | {
9 | public class MdbCharacter
10 | {
11 | private static MdbCharacter Instance;
12 |
13 | public static MdbCharacter GetInstance()
14 | {
15 | return (Instance != null) ? Instance : Instance = new MdbCharacter();
16 | }
17 |
18 | private MongoClient m_Client;
19 | private MongoServer m_Server;
20 | private MongoDatabase m_Database;
21 | private MongoCollection m_Collection;
22 |
23 | private string MDBTable = "characters";
24 |
25 | public MdbCharacter()
26 | {
27 | m_Client = new MongoClient(Configuration.Database.Url);
28 | m_Server = m_Client.GetServer();
29 | m_Database = m_Server.GetDatabase(Configuration.Database.Name);
30 | m_Collection = m_Database.GetCollection(MDBTable);
31 | }
32 |
33 | public void AddCharacter(Character Char)
34 | {
35 | m_Collection.Insert(Char);
36 | }
37 |
38 | public Dictionary GetAccountCharacter(string AccountName)
39 | {
40 | var query = Query.EQ(c => c.AccountName, AccountName);
41 | var characters = m_Collection.Find(query);
42 |
43 | if (characters.Count() <= 0)
44 | return null;
45 |
46 | Dictionary list = new Dictionary();
47 | int i = 0;
48 | foreach (var character in characters)
49 | {
50 | list.Add(i, character);
51 | i++;
52 | }
53 |
54 | return list;
55 | }
56 |
57 | public bool IsAvailableName(string name)
58 | {
59 | var query = Query.EQ(c => c.Name, name);
60 | long num = m_Collection.Find(query).Count();
61 | return (num <= 0) ? true : false;
62 | }
63 |
64 | internal bool DeleteCharacter(string name)
65 | {
66 | var query = Query.EQ(c => c.Name, name);
67 | var result = m_Collection.Remove(query);
68 | return result.Ok;
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/GameServer/Network/ClientManager.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using Common.Utilities;
3 | using GameServer.Config;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Net.Sockets;
8 |
9 | namespace GameServer.Network
10 | {
11 | internal class ClientManager
12 | {
13 | private static ClientManager Instance = new ClientManager();
14 | private Dictionary> _Clients = new Dictionary>();
15 |
16 | private IDFactory IDFactory;
17 |
18 | static ClientManager()
19 | {
20 | }
21 |
22 | public ClientManager()
23 | {
24 | foreach(ChannelStruct chn in Configuration.GetInstance().Channels)
25 | {
26 | _Clients.Add(chn.Id, new List());
27 | }
28 | IDFactory = new IDFactory(0);
29 | Log.Info("ClientManager Loaded");
30 | }
31 |
32 | public static ClientManager GetInstance()
33 | {
34 | return ClientManager.Instance;
35 | }
36 |
37 | public void AddClient(TcpClient tcp)
38 | {
39 | // todo block ip
40 | string ip = tcp.Client.RemoteEndPoint.ToString().Split(':')[0];
41 | int local_port = Convert.ToInt32(tcp.Client.LocalEndPoint.ToString().Split(':')[1]);
42 |
43 | int chnId = Configuration.GetInstance().Channels
44 | .Where(c => c.Port == local_port)
45 | .Select(v => v.Id).FirstOrDefault();
46 |
47 | Client client = new Client(tcp);
48 | client.SessID = (short)IDFactory.GetNext();
49 |
50 | if (_Clients[chnId].Contains(client))
51 | Log.Warn("Client is already exists!");
52 | else
53 | _Clients[chnId].Add(client);
54 | }
55 |
56 | public void RemoveClient(Client loginClient)
57 | {
58 | int local_port = Convert.ToInt32(loginClient._client.Client.LocalEndPoint.ToString().Split(':')[1]);
59 | int chnId = Configuration.GetInstance().Channels
60 | .Where(c => c.Port == local_port)
61 | .Select(v => v.Id).FirstOrDefault();
62 |
63 | if (!_Clients[chnId].Contains(loginClient))
64 | return;
65 |
66 | _Clients[chnId].Remove(loginClient);
67 | }
68 |
69 | public int GetUserOnlineCount(int channelId)
70 | {
71 | return _Clients[channelId].Count;
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/GameServer/Model/Creature/CreatureBaseStats.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Model.Character;
2 | using ProtoBuf;
3 | using System.ComponentModel;
4 |
5 | namespace GameServer.Model.Creature
6 | {
7 | [ProtoContract]
8 | public class CreatureBaseStats
9 | {
10 | [Category("Commons"), ProtoMember(1)]
11 | public CharacterClass PlayerClass { get; set; }
12 | [Category("Commons"), ProtoMember(2)]
13 | public int Level { get; set; }
14 | [Category("Commons"), ProtoMember(3)]
15 | public long Exp { get; set; }
16 |
17 |
18 |
19 | [Category("LifeStats"), ProtoMember(10)]
20 | public int HpBase { get; set; }
21 | [Category("LifeStats"), ProtoMember(11)]
22 | public int MpBase { get; set; }
23 | [Category("LifeStats"), ProtoMember(12)]
24 | public int SpBase { get; set; }
25 |
26 |
27 |
28 | [Category("Combat"), ProtoMember(20)]
29 | public int Attack { get; set; }
30 | [Category("Combat"), ProtoMember(21)]
31 | public int SkillAttack { get; set; }
32 | [Category("Combat"), ProtoMember(22)]
33 | public int Defense { get; set; }
34 | [Category("Combat"), ProtoMember(23)]
35 | public int SkillDefense { get; set; }
36 | [Category("Combat"), ProtoMember(24)]
37 | public int Accuracy { get; set; }
38 | [Category("Combat"), ProtoMember(25)]
39 | public int Dodge { get; set; }
40 |
41 |
42 |
43 | [Category("Stats"), ProtoMember(30)]
44 | public int Spirit { get; set; }
45 | [Category("Stats"), ProtoMember(31)]
46 | public int Strength { get; set; }
47 | [Category("Stats"), ProtoMember(32)]
48 | public int Stamina { get; set; }
49 | [Category("Stats"), ProtoMember(33)]
50 | public int Dexterity { get; set; }
51 |
52 |
53 | public CreatureBaseStats Clone()
54 | {
55 | return (CreatureBaseStats)MemberwiseClone();
56 | }
57 |
58 | public void CopyTo(CreatureBaseStats gameStats)
59 | {
60 | //HpMp
61 | gameStats.HpBase = HpBase;
62 | gameStats.MpBase = MpBase;
63 | gameStats.SpBase = SpBase;
64 |
65 | //Combat
66 | gameStats.Attack = Attack;
67 | gameStats.SkillAttack = SkillAttack;
68 | gameStats.Defense = Defense;
69 | gameStats.SkillDefense = SkillDefense;
70 | gameStats.Accuracy = Accuracy;
71 | gameStats.Dodge = Dodge;
72 |
73 | //Stats
74 | gameStats.Spirit = Spirit;
75 | gameStats.Strength = Strength;
76 | gameStats.Stamina = Stamina;
77 | gameStats.Dexterity = Dexterity;
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/GameServer/DataHolder/Data.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using GameServer.Model.Creature;
3 | using ProtoBuf;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Diagnostics;
7 | using System.IO;
8 | using System.Threading.Tasks;
9 |
10 | namespace GameServer.DataHolder
11 | {
12 | public class Data
13 | {
14 | public static string DataPath = Path.GetFullPath("data/");
15 |
16 | public static List Stats = new List();
17 |
18 | protected delegate int Loader();
19 |
20 | protected static List Loaders = new List
21 | {
22 | //LoadMapTemplates,
23 | //LoadPlayerExperience,
24 | LoadBaseStats,
25 | //LoadItemTemplates,
26 | //LoadSpawns,
27 | //LoadBindPoints,
28 | //LoadNpcTemplates,
29 | //LoadQuests,
30 | //LoadSkills,
31 | //LoadAbilities,
32 | //LoadAbnormalities,
33 | //LoadDrop,
34 | //LoadTeleports,
35 | //CalculateNpcExperience,
36 | };
37 |
38 | public static void LoadAll()
39 | {
40 | Console.WriteLine("Load All Data holders...");
41 | Console.WriteLine("-------------------------------------------");
42 |
43 | Parallel.For(0, Loaders.Count, i => LoadTask(Loaders[i]));
44 |
45 | Console.WriteLine("\n-------------------------------------------\n");
46 | }
47 |
48 | private static void LoadTask(Loader loader)
49 | {
50 | Stopwatch stopwatch = Stopwatch.StartNew();
51 | int readed = loader.Invoke();
52 | stopwatch.Stop();
53 |
54 | Log.Info("Data: {0,-26} {1,7} values in {2}s"
55 | , loader.Method.Name
56 | , readed
57 | , (stopwatch.ElapsedMilliseconds / 1000.0).ToString("0.00"));
58 | }
59 |
60 | public static int LoadBaseStats()
61 | {
62 | using (FileStream fs = File.OpenRead(DataPath + "stats.bin"))
63 | {
64 | Stats = Serializer.DeserializeWithLengthPrefix>(fs, PrefixStyle.Fixed32);
65 | }
66 |
67 | return Stats.Count;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Common/Common.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {2CC06D57-6A68-473D-A7ED-D19CA8381B57}
8 | Library
9 | Properties
10 | Common
11 | Common
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 | ..\packages\NLog.2.1.0\lib\net45\NLog.dll
35 |
36 |
37 | ..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | PreserveNewest
58 |
59 |
60 |
61 |
62 |
69 |
--------------------------------------------------------------------------------
/GameServer/Service/CharacterService.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using GameServer.Config;
3 | using GameServer.Database;
4 | using GameServer.Model.Account;
5 | using GameServer.Model.Character;
6 | using GameServer.Network.Send;
7 | using System;
8 |
9 | namespace GameServer.Service
10 | {
11 | public class CharacterService
12 | {
13 | private static CharacterService Instance;
14 |
15 | internal void SendCharacterList(Account account)
16 | {
17 | account._Characters = MdbCharacter.GetInstance().GetAccountCharacter(account.Name);
18 |
19 | if (account._Characters == null)
20 | account._Client.SendPacket(new ResponseCharacterList());
21 | else
22 | foreach (var character in account._Characters)
23 | account._Client.SendPacket(new ResponseCharacterList(character));
24 | }
25 |
26 | internal static CharacterService GetInstance()
27 | {
28 | return (Instance != null) ? Instance : Instance = new CharacterService();
29 | }
30 |
31 | internal void SendCheckName(Account account, string Name)
32 | {
33 | bool result = MdbCharacter.GetInstance().IsAvailableName(Name);
34 | account._Client.SendPacket(new ResponseCheckName(Name, result));
35 | }
36 |
37 | internal void CreateCharacter(Account account, Character Character)
38 | {
39 | Character.AccountName = account.Name;
40 | Character.ServerId = Configuration.Setting.ServerId;
41 | Character.Level = 1;
42 | Character.JobLevel = 1;
43 | Character.NameStyle = "0000000000000000FFFFFFFFFFFFFFFF0100000000000000FFFFFFFFFFFFFFFF0200000000000000FFFFFFFFFFFFFFFF".ToBytes();
44 | Character.GameStats = StatsService.GetInstance().InitStats(Character);
45 | Character.Position = new Model.Map.MapPosition()
46 | {
47 | MapId = 101,
48 | X = BitConverter.GetBytes(300.0F),
49 | Y = BitConverter.GetBytes(1865.0F),
50 | Z = BitConverter.GetBytes(15.0F),
51 | oldX = new byte[0],
52 | oldY = new byte[0],
53 | oldZ = new byte[0],
54 | };
55 |
56 | MdbCharacter.GetInstance().AddCharacter(Character);
57 |
58 | account._Client.SendPacket(new ResponseCreateCharacter(1));
59 | }
60 |
61 | internal void DeleteCharacter(Account account, string deletepw, string charname)
62 | {
63 | if (account.DeletePasswd != deletepw)
64 | account._Client.SendPacket(new ResponseDeleteCharacter(false));
65 |
66 | bool result = MdbCharacter.GetInstance().DeleteCharacter(charname);
67 |
68 | account._Client.SendPacket(new ResponseDeleteCharacter(result));
69 | }
70 |
71 | internal void CharacterEnterGame(Network.Client _Client)
72 | {
73 | Character character = _Client._Char;
74 |
75 | new ResponseServerTime(0).Send(_Client);
76 | new ResponseRunning().Send(_Client);
77 | new ResponseCharacterInfo(character).Send(_Client);
78 |
79 | new ResponseSetBuff(2, 1, 1).Send(_Client);
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseCharacterList.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Model.Character;
2 | using GameServer.Model.Item;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace GameServer.Network.Send
10 | {
11 | public class ResponseCharacterList : ASendPacket
12 | {
13 | protected bool Exists;
14 | private KeyValuePair Kvp;
15 |
16 | public ResponseCharacterList()
17 | {
18 | Exists = false;
19 | }
20 |
21 | public ResponseCharacterList(KeyValuePair kvp)
22 | {
23 | Exists = true;
24 | Kvp = kvp;
25 | }
26 |
27 | protected internal override void Write()
28 | {
29 | if (!Exists)
30 | WriteC(0xff);
31 | else
32 | {
33 | var character = Kvp.Value;
34 |
35 | WriteC((byte)Kvp.Key);
36 | WriteS(character.Name, 15);
37 | WriteC(0);
38 | WriteD(0);
39 | WriteS("", 15);
40 | WriteC(0);
41 | WriteH(0);
42 |
43 | WriteH(0);
44 | WriteH(character.Level);
45 |
46 | WriteC((byte)character.Forces);
47 | WriteC(0); // famous
48 | WriteC((byte)character.Class);
49 |
50 | WriteC((byte)character.HairStyle);
51 | WriteC((byte)character.HairColor);
52 | WriteC((byte)character.Face);
53 | WriteC((byte)character.Voice);
54 | WriteC(0);
55 | WriteC((byte)character.Title);
56 | WriteC((byte)character.Gender);
57 |
58 | WriteB(character.Position.X);
59 | WriteB(character.Position.Z);
60 | WriteB(character.Position.Y);
61 | WriteD(character.Position.MapId);
62 |
63 | WriteB(new byte[12]);
64 |
65 | WriteB(character.NameStyle);
66 |
67 | WriteB(new byte[8]);
68 |
69 | WriteH(character.GameStats.HpBase); // MaxHp
70 | WriteH(character.GameStats.MpBase); // MaxMp
71 | WriteD(character.GameStats.SpBase); // MaxSp
72 | WriteQ(character.GameStats.Exp); // Exp
73 |
74 | WriteH(character.LifeStats.Hp); // current Hp
75 | WriteH(character.LifeStats.Mp); // current Mp
76 | WriteD(character.LifeStats.Sp); // current Sp
77 | WriteQ(character.Exp); // current Exp
78 |
79 | WriteD(0);
80 | WriteB(new byte[16]);
81 |
82 | for (int i = 0; i < 30; i++ )
83 | {
84 | StorageItem item;
85 | try
86 | {
87 | item = character.Equipment.Items.Values.ToList()[i];
88 | }
89 | catch
90 | {
91 | item = null;
92 | }
93 |
94 | if (item == null)
95 | WriteB(new byte[88]);
96 | else
97 | WriteItemInfo(item);
98 | }
99 | }
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/GameServer/Config/Configuration.cs:
--------------------------------------------------------------------------------
1 | using Common.Model.Server;
2 | using Common.Utilities;
3 | using Nini.Config;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace GameServer.Config
11 | {
12 | public class Configuration
13 | {
14 | private static Configuration Instance;
15 |
16 | private static IConfig _DBCfg = new IniConfigSource("Config/database.ini").Configs["database"];
17 | private static IConfig _NWCfg = new IniConfigSource("Config/network.ini").Configs["network"];
18 | private static IConfig _STCfg = new IniConfigSource("Config/setting.ini").Configs["setting"];
19 |
20 | private static IConfigSource _CNSource = new IniConfigSource("Config/channel.ini");
21 |
22 | public static DatabaseStruct Database;
23 | public static NetworkStruct Network;
24 | public static SettingStruct Setting;
25 |
26 | public List Channels = new List(10);
27 |
28 | public Configuration()
29 | {
30 | Console.WriteLine("Load All Configuration...");
31 | Console.WriteLine("-------------------------------------------");
32 |
33 | Database = new DatabaseStruct(
34 | _DBCfg.GetString("db.mongo.url"),
35 | _DBCfg.GetString("db.mongo.name")
36 | );
37 | Log.Info("Loaded Database Configuration");
38 |
39 | Network = new NetworkStruct(
40 | _NWCfg.GetString("public.ip"),
41 | _NWCfg.GetString("private.ip"),
42 | _NWCfg.GetInt("private.port"),
43 | _NWCfg.GetString("login.ip"),
44 | _NWCfg.GetInt("login.port")
45 | );
46 | Log.Info("Loaded Network Configuration");
47 |
48 | Setting = new SettingStruct(
49 | _STCfg.GetInt("server.id"),
50 | _STCfg.GetString("server.name"),
51 | _STCfg.GetBoolean("server.Akey"),
52 | _STCfg.GetBoolean("debuging"),
53 | _STCfg.GetInt("rate.exp"),
54 | _STCfg.GetInt("rate.money"),
55 | _STCfg.GetInt("rate.sp")
56 | );
57 | Log.Info("Loaded Setting Configuration");
58 |
59 | Console.WriteLine("\n-------------------------------------------\n");
60 |
61 | Console.WriteLine("Load Channels Configuration...");
62 | Console.WriteLine("-------------------------------------------");
63 | for(int i = 0; i < 10; i++)
64 | {
65 | int id = (i + 1);
66 | var cConfig = _CNSource.Configs["channel" + id];
67 | if (cConfig == null)
68 | continue;
69 |
70 | Channels.Add(new ChannelStruct(
71 | id,
72 | cConfig.GetString("channel.name"),
73 | cConfig.GetInt("channel.port"),
74 | cConfig.GetInt("channel.type"),
75 | cConfig.GetInt("channel.max")
76 | ));
77 |
78 | Log.Info("Channel: {0} Loaded", id);
79 | }
80 | Console.WriteLine("\n-------------------------------------------\n");
81 | }
82 |
83 | public static Configuration GetInstance()
84 | {
85 | return (Instance != null) ? Instance : Instance = Instance = new Configuration();
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/LoginServer/Network/ARecvPacket.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System;
3 | using System.Text;
4 |
5 | namespace LoginServer.Network
6 | {
7 | public abstract class ARecvPacket
8 | {
9 | private byte[] _buffer;
10 | private int _offset;
11 | protected Client _Client;
12 |
13 | protected internal Client GetClient()
14 | {
15 | return _Client;
16 | }
17 |
18 | protected internal byte[] GetBuffer()
19 | {
20 | return this._buffer;
21 | }
22 |
23 | protected internal void execute(Client Client, byte[] buffer)
24 | {
25 | _Client = Client;
26 | _buffer = buffer;
27 | _offset = 4;
28 | Read();
29 | Run();
30 | }
31 |
32 | protected internal int ReadD()
33 | {
34 | int num = BitConverter.ToInt32(this._buffer, this._offset);
35 | this._offset += 4;
36 | return num;
37 | }
38 |
39 | protected internal byte ReadC()
40 | {
41 | byte num = this._buffer[this._offset];
42 | ++this._offset;
43 | return num;
44 | }
45 |
46 | protected internal byte[] ReadB(int Length)
47 | {
48 | byte[] numArray = new byte[Length];
49 | Array.Copy((Array)this._buffer, this._offset, (Array)numArray, 0, Length);
50 | this._offset += Length;
51 | return numArray;
52 | }
53 |
54 | protected internal short ReadH()
55 | {
56 | short num = BitConverter.ToInt16(this._buffer, this._offset);
57 | this._offset += 2;
58 | return num;
59 | }
60 |
61 | protected internal double ReadF()
62 | {
63 | double num = BitConverter.ToDouble(this._buffer, this._offset);
64 | this._offset += 8;
65 | return num;
66 | }
67 |
68 | protected internal long ReadQ()
69 | {
70 | long num = BitConverter.ToInt64(this._buffer, this._offset);
71 | this._offset += 8;
72 | return num;
73 | }
74 |
75 | protected internal string ReadS(int Length)
76 | {
77 | string str = "";
78 | try
79 | {
80 | str = Encoding.Default.GetString(this._buffer, this._offset, Length);
81 | int length = str.IndexOf(char.MinValue);
82 | if (length != -1)
83 | str = str.Substring(0, length);
84 | this._offset += Length;
85 | }
86 | catch (Exception ex)
87 | {
88 | Log.ErrorException("while reading string from packet", ex);
89 | }
90 | return str;
91 | }
92 |
93 | protected internal string ReadS()
94 | {
95 | string str = "";
96 | try
97 | {
98 | int len = ReadH();
99 | str = ReadS(len); ;
100 | }
101 | catch (Exception ex)
102 | {
103 | Log.ErrorException("while reading string from packet", ex);
104 | }
105 | return str;
106 | }
107 |
108 | protected internal void Ignore(int in_offset)
109 | {
110 | this._offset = this._offset + in_offset;
111 | Log.Trace("Ignore {0} bytes", in_offset);
112 | }
113 |
114 | protected internal abstract void Read();
115 |
116 | protected internal abstract void Run();
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/GSARecvPacket.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace LoginServer.Network.GameServer
9 | {
10 | public abstract class GSARecvPacket
11 | {
12 | private byte[] _buffer;
13 | private int _offset;
14 | protected GSClient _Client;
15 |
16 | protected internal GSClient GetClient()
17 | {
18 | return _Client;
19 | }
20 |
21 | protected internal byte[] GetBuffer()
22 | {
23 | return this._buffer;
24 | }
25 |
26 | protected internal void execute(GSClient Client, byte[] buffer)
27 | {
28 | _Client = Client;
29 | _buffer = buffer;
30 | _offset = 4;
31 | Read();
32 | Run();
33 | }
34 |
35 | protected internal int ReadD()
36 | {
37 | int num = BitConverter.ToInt32(this._buffer, this._offset);
38 | this._offset += 4;
39 | return num;
40 | }
41 |
42 | protected internal byte ReadC()
43 | {
44 | byte num = this._buffer[this._offset];
45 | ++this._offset;
46 | return num;
47 | }
48 |
49 | protected internal byte[] ReadB(int Length)
50 | {
51 | byte[] numArray = new byte[Length];
52 | Array.Copy((Array)this._buffer, this._offset, (Array)numArray, 0, Length);
53 | this._offset += Length;
54 | return numArray;
55 | }
56 |
57 | protected internal short ReadH()
58 | {
59 | short num = BitConverter.ToInt16(this._buffer, this._offset);
60 | this._offset += 2;
61 | return num;
62 | }
63 |
64 | protected internal double ReadF()
65 | {
66 | double num = BitConverter.ToDouble(this._buffer, this._offset);
67 | this._offset += 8;
68 | return num;
69 | }
70 |
71 | protected internal long ReadQ()
72 | {
73 | long num = BitConverter.ToInt64(this._buffer, this._offset);
74 | this._offset += 8;
75 | return num;
76 | }
77 |
78 | protected internal string ReadS(int Length)
79 | {
80 | string str = "";
81 | try
82 | {
83 | str = Encoding.Default.GetString(this._buffer, this._offset, Length);
84 | int length = str.IndexOf(char.MinValue);
85 | if (length != -1)
86 | str = str.Substring(0, length);
87 | this._offset += Length;
88 | }
89 | catch (Exception ex)
90 | {
91 | Log.ErrorException("while reading string from packet", ex);
92 | }
93 | return str;
94 | }
95 |
96 | protected internal string ReadS()
97 | {
98 | string str = "";
99 | try
100 | {
101 | int len = ReadH();
102 | str = ReadS(len);
103 | }
104 | catch (Exception ex)
105 | {
106 | Log.ErrorException("while reading string from packet", ex);
107 | }
108 | return str;
109 | }
110 |
111 | protected internal void Ignore(int in_offset)
112 | {
113 | this._offset = this._offset + in_offset;
114 | Log.Trace("Ignore {0} bytes", in_offset);
115 | }
116 |
117 | protected internal abstract void Read();
118 |
119 | protected internal abstract void Run();
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/GameServer/Network/Send/ResponseCharacterInfo.cs:
--------------------------------------------------------------------------------
1 | using GameServer.Model.Account;
2 | using GameServer.Model.Character;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace GameServer.Network.Send
10 | {
11 | public class ResponseCharacterInfo : ASendPacket
12 | {
13 | protected Character Character;
14 | public ResponseCharacterInfo(Character c)
15 | {
16 | Character = c;
17 | }
18 |
19 | protected internal override void Write()
20 | {
21 | WriteD(1);
22 |
23 | WriteD(_Client.SessID);
24 | WriteS(Character.Name, 15);
25 | WriteC(0);
26 |
27 | WriteD(0); // Guild ID
28 | WriteS(string.Empty, 15); // Guild Name
29 | WriteC(0); //Guild Level
30 |
31 | WriteH(0); // SERVER ID ?
32 |
33 | WriteC(Character.Forces);
34 | WriteC(Character.Level);
35 | WriteC(Character.JobLevel); // Job Level
36 | WriteC((byte)Character.Class);
37 |
38 | WriteC(1);
39 | WriteC(0);
40 |
41 | WriteH(Character.HairColor);
42 | WriteH(Character.HairStyle);
43 | WriteC(1);
44 | WriteC((byte)Character.Gender);
45 |
46 | WriteH(0);
47 |
48 | WriteB(Character.Position.X);
49 | WriteB(Character.Position.Z);
50 | WriteB(Character.Position.Y);
51 | WriteD(Character.Position.MapId);
52 |
53 | var equips = Character.Equipment.Items;
54 |
55 | WriteQ(/*(equips[0] != null) ? equips[0].ItemId : */0); // Equip slot 0
56 | WriteQ(/*(equips[1] != null) ? equips[1].ItemId : */0); // Equip slot 1
57 | WriteQ(/*(equips[2] != null) ? equips[2].ItemId : */0); // Equip slot 2
58 | WriteQ(/*(equips[4] != null) ? equips[4].ItemId : */0); // Equip slot 4
59 | WriteQ(/*(equips[3] != null) ? equips[3].ItemId : */0); // Equip slot 3
60 | WriteQ(/*(equips[5] != null) ? equips[5].ItemId : */0); // Equip slot 5
61 | WriteD(/*(equips[3] != null) ? equips[3].Upgrade : */0); // Equip slot 3 LevelUpgrade
62 | WriteQ(/*(equips[11] != null) ? equips[11].ItemId : */0); // Equip slot 11
63 |
64 | int setting = AccountSetting.GetSettings(_Client._Account.Setting);
65 | WriteC(setting);
66 | WriteC(_Client._Account.Setting.FameSwitch);
67 | WriteH(0);
68 |
69 | WriteB(Character.Position.oldX);
70 | WriteB(Character.Position.oldZ);
71 | WriteB(Character.Position.oldY);
72 |
73 | WriteD(0);
74 | WriteD(0);
75 |
76 | WriteD(0xff); // PET
77 | WriteD(0);
78 | WriteQ(/*(equips[13] != null) ? equips[13].ItemId : */0); // Equip slot 13
79 |
80 | WriteH(0); // Word gang door service
81 | WriteH(0); // Gang colors door service
82 |
83 | WriteD(Character.HonorPoint); // Character_WuXun
84 | WriteD(1); // Forces side
85 |
86 | WriteD(0); // People head picture
87 | WriteD(0); // StealthMode
88 |
89 | WriteB(Character.NameStyle);
90 |
91 | WriteD(1);
92 |
93 | // Maried
94 | WriteC(0);
95 | WriteS(string.Empty, 15);
96 |
97 | WriteH(0);
98 | WriteH(0);
99 | WriteH(0);
100 | WriteH(0);
101 | WriteH(0);
102 |
103 | WriteC(0);
104 | WriteC(0);
105 | WriteC(0);
106 | WriteC(0);
107 |
108 | WriteH(0);
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/packages/protobuf-net.2.0.0.668/protobuf-net.2.0.0.668.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | protobuf-net
5 | 2.0.0.668
6 | Marc Gravell
7 | Marc Gravell
8 | http://protobuf-net.googlecode.com/svn/trunk/Licence.txt
9 | http://code.google.com/p/protobuf-net/
10 | false
11 | Protocol Buffers is the name of the binary serialization format used by Google for much of their data communications. It is designed to be: small in size - efficient data storage (far smaller than xml) cheap to process - both at the client and server platform independent - portable between different programming architectures extensible - to add new data to old messages. protobuf-net is a .NET implementation of this, allowing you to serialize your .NET objects efficiently and easily. It is compatible with most of the .NET family, including .NET 2.0/3.0/3.5/4.0, .NET CF 2.0/3.5, Mono 2.x, Silverlight, etc.
12 | Provides simple access to fast and efficient "Protocol Buffers" serialization from .NET applications
13 | * 2.0.0.668 - fix: reader's position not resetting: eventually causes overflow on pooled instance; critical fix to 663
14 | * 2.0.0.666 - add: Support for BCL immutable types (Microsoft.Bcl.Immutable)
15 | * 2.0.0.664 - add: Remove some more allocations (IPredicate)
16 | * 2.0.0.663 - add: ProtoReader recycling for heavy read throughput
17 | - add: precompile uses alternative switch construct (android limitations)
18 | * 2.0.0.651 - add: new key-signing options for precompile
19 | - add: enum-passthru defaults
20 | * 2.0.0.640 - fix: bug with length-prefix / naked enumerations
21 | * 2.0.0.638 - update: protoc 2.5
22 | - fix: various tweaks for Genderme
23 | - fix: better support for "naked enumerables" (root enumerable objects)
24 | * 2.0.0.627 - fix: bug in "precompiler" for lots of types
25 | - add: support for default type factories (including extended callback signature support)
26 | - fix: ImplicitFields parsing failing if assembly loaded dynamically
27 | - add: experimental support for concurrent collections
28 | - add: support for tuples with AsReference; better handling of default AsReference; improved AsReference error message
29 | * 2.0.0.622 - fix: bug in protogen with default enums when no package is specified
30 | * 2.0.0.621 - fix: nasty regression in r619, where GetSchema() could cause base-type corruption
31 | * 2.0.0.619 - fix: GetSchema() should use ultimate base-type names when modelling inheritance
32 | - fix: ensure precomile always generates a .ctor() on the concrete serializer
33 | - add: support out-of-order fields when deseiralizing inheritance from other protobuf implementations
34 | * 2.0.0.614 - fix: enum handling of ": byte" confusing signed/unsigned bytes
35 | * 2.0.0.612 - fix: allow adding enum maps at runtime via MetaType
36 | * 2.0.0.611 - fix: *Specified should work with non-public methods
37 | - performance: pre-compiled serializers now use dictionary lookups where appropriate
38 | - fix: nuget package for portable library should be more inclusive
39 | * 2.0.0.602 - added precompiler support for internal-types and [InternalsVisibleTo(...)]-forwarding
40 | - made AllowParseableTypes available on default type-model
41 | * 2.0.0.601 - added phone8 support
42 | en-US
43 | binary serialization protocol buffers protobuf deserialization
44 |
45 |
--------------------------------------------------------------------------------
/GameServer/Network/LoginServer/LSARecvPacket.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace GameServer.Network.LoginServer
8 | {
9 | public abstract class LSARecvPacket
10 | {
11 | private byte[] _buffer;
12 | private int _offset;
13 | protected LSClient _Client;
14 |
15 | protected internal LSClient GetClient()
16 | {
17 | return _Client;
18 | }
19 |
20 | protected internal byte[] GetBuffer()
21 | {
22 | return this._buffer;
23 | }
24 |
25 | protected internal void execute(LSClient Client, byte[] buffer)
26 | {
27 | _Client = Client;
28 | _buffer = buffer;
29 | _offset = 2;
30 | Read();
31 | Run();
32 | }
33 |
34 | protected internal int ReadD()
35 | {
36 | int num = BitConverter.ToInt32(this._buffer, this._offset);
37 | this._offset += 4;
38 | return num;
39 | }
40 |
41 | protected internal byte ReadC()
42 | {
43 | byte num = this._buffer[this._offset];
44 | ++this._offset;
45 | return num;
46 | }
47 |
48 | protected internal byte[] ReadB(int Length)
49 | {
50 | byte[] numArray = new byte[Length];
51 | Array.Copy((Array)this._buffer, this._offset, (Array)numArray, 0, Length);
52 | this._offset += Length;
53 | return numArray;
54 | }
55 |
56 | protected internal short ReadH()
57 | {
58 | short num = BitConverter.ToInt16(this._buffer, this._offset);
59 | this._offset += 2;
60 | return num;
61 | }
62 |
63 | protected internal double ReadF()
64 | {
65 | double num = BitConverter.ToDouble(this._buffer, this._offset);
66 | this._offset += 8;
67 | return num;
68 | }
69 |
70 | protected internal long ReadQ()
71 | {
72 | long num = BitConverter.ToInt64(this._buffer, this._offset);
73 | this._offset += 8;
74 | return num;
75 | }
76 |
77 | protected internal string ReadS(int Length)
78 | {
79 | string str = "";
80 | try
81 | {
82 | str = Encoding.Default.GetString(this._buffer, this._offset, Length);
83 | int length = str.IndexOf(char.MinValue);
84 | if (length != -1)
85 | str = str.Substring(0, length);
86 | this._offset += Length;
87 | }
88 | catch (Exception ex)
89 | {
90 | Log.ErrorException("while reading string from packet", ex);
91 | }
92 | return str;
93 | }
94 |
95 | protected internal string ReadS()
96 | {
97 | string str = "";
98 | try
99 | {
100 | str = Encoding.Default.GetString(this._buffer, this._offset, this._buffer.Length - this._offset);
101 | int length = str.IndexOf(char.MinValue);
102 | if (length != -1)
103 | str = str.Substring(0, length);
104 | this._offset += str.Length + 1;
105 | }
106 | catch (Exception ex)
107 | {
108 | Log.ErrorException("while reading string from packet", ex);
109 | }
110 | return str;
111 | }
112 |
113 | protected internal void Ignore(int in_offset)
114 | {
115 | this._offset = this._offset + in_offset;
116 | Log.Trace("Ignore {0} bytes", in_offset);
117 | }
118 |
119 | protected internal int Length
120 | {
121 | get
122 | {
123 | return BitConverter.ToInt16(new byte[2] { _buffer[2], _buffer[3] }, 0);
124 | }
125 | }
126 |
127 | protected internal abstract void Read();
128 |
129 | protected internal abstract void Run();
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/GameServer/Model/Creature/CreatureLifeStats.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace GameServer.Model.Creature
8 | {
9 | public class CreatureLifeStats
10 | {
11 | public Creature Creature;
12 |
13 | public bool SendUpdate = true;
14 |
15 | private int _hp;
16 |
17 | public int Hp
18 | {
19 | get { return _hp; }
20 | set { _hp = value; }
21 | }
22 |
23 | private int _mp;
24 |
25 | public int Mp
26 | {
27 | get { return _mp; }
28 | set { _mp = value; }
29 | }
30 |
31 | private int _sp;
32 |
33 | public int Sp
34 | {
35 | get { return _sp; }
36 | set { _sp = value; }
37 | }
38 |
39 | public bool IsDead()
40 | {
41 | if (Hp <= 0)
42 | return true;
43 |
44 | return false;
45 | }
46 |
47 | public bool IsRage()
48 | {
49 | if (Sp >= Creature.GameStats.SpBase)
50 | {
51 | Sp = 0;
52 | return true;
53 | }
54 |
55 | return false;
56 | }
57 |
58 | public CreatureLifeStats(Creature creature)
59 | {
60 | _hp = creature.GameStats.HpBase;
61 | _mp = creature.GameStats.MpBase;
62 | _sp = 0;
63 |
64 | Creature = creature;
65 | }
66 |
67 | public int PlusHp(int value)
68 | {
69 | _hp += value;
70 |
71 | if (_hp > Creature.MaxHp)
72 | {
73 | value -= _hp - Creature.MaxHp;
74 | _hp = Creature.MaxHp;
75 | }
76 |
77 | return value;
78 | }
79 |
80 | public int GetHpDiffResult(int value)
81 | {
82 | return _hp - value;
83 | }
84 |
85 | public int MinusHp(int value)
86 | {
87 | _hp -= value;
88 |
89 | if (_hp < 0)
90 | {
91 | value += _hp;
92 | _hp = 0;
93 | }
94 |
95 | return -value;
96 | }
97 |
98 | public int PlusMp(int value)
99 | {
100 | _mp += value;
101 |
102 | if (_mp > Creature.MaxMp)
103 | {
104 | value -= _mp - Creature.MaxMp;
105 | _mp = Creature.MaxMp;
106 | }
107 |
108 | return value;
109 | }
110 |
111 | public int MinusMp(int value)
112 | {
113 | _mp -= value;
114 |
115 | if (_mp < 0)
116 | {
117 | value += _mp;
118 | _mp = 0;
119 | }
120 |
121 | return -value;
122 | }
123 |
124 | public int PlusSp(int value)
125 | {
126 | _sp += value;
127 |
128 | if (_sp > Creature.MaxSp)
129 | {
130 | value -= _sp - Creature.MaxSp;
131 | _sp = Creature.MaxSp;
132 | }
133 |
134 | return value;
135 | }
136 |
137 | public int MinusSp(int value)
138 | {
139 | _sp -= value;
140 |
141 | if (_sp < 0)
142 | {
143 | value += _sp;
144 | _sp = 0;
145 | }
146 |
147 | return -value;
148 | }
149 |
150 | public void Kill()
151 | {
152 | _hp = 0;
153 | _mp = 0;
154 | _sp = 0;
155 |
156 | }
157 |
158 | public void Rebirth()
159 | {
160 | _hp = Creature.GameStats.HpBase;
161 | _mp = Creature.GameStats.MpBase;
162 |
163 | //if (Creature is Npc.Npc)
164 | // return;
165 |
166 | _hp /= 10;
167 | _mp /= 10;
168 | }
169 |
170 | public void LevelUp()
171 | {
172 | _hp = Creature.GameStats.HpBase;
173 | _mp = Creature.GameStats.MpBase;
174 | }
175 |
176 | public CreatureLifeStats Clone()
177 | {
178 | return (CreatureLifeStats)MemberwiseClone();
179 | }
180 |
181 | public void Release()
182 | {
183 | Creature = null;
184 | }
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/Common/Utilities/Funcs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Text;
4 |
5 | namespace Common.Utilities
6 | {
7 | public static class Funcs
8 | {
9 | private static readonly string[] Baths;
10 | private static readonly DateTime StaticDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
11 | private static readonly Random Randomizer = new Random((int)DateTime.Now.Ticks);
12 |
13 | static Funcs()
14 | {
15 | Baths = new string[256];
16 | for (int i = 0; i < 256; i++)
17 | Baths[i] = String.Format("{0:X2}", i);
18 | }
19 |
20 | public static Random Random()
21 | {
22 | return Randomizer;
23 | }
24 |
25 | public static byte[] NextBytes(int len)
26 | {
27 | byte[] rand = new byte[len];
28 | Random().NextBytes(rand);
29 | return rand;
30 | }
31 |
32 | public static int GetRoundedLocal()
33 | {
34 | // ReSharper disable PossibleLossOfFraction
35 | return (int)Math.Round((double)(GetCurrentMilliseconds() / 1000));
36 | // ReSharper restore PossibleLossOfFraction
37 | }
38 |
39 | public static long GetCurrentMilliseconds()
40 | {
41 | return (long)(DateTime.Now - StaticDate).TotalMilliseconds;
42 | }
43 |
44 | public static string ToHex(this byte[] array)
45 | {
46 | StringBuilder builder = new StringBuilder(array.Length * 2);
47 |
48 | for (int i = 0; i < array.Length; i++)
49 | builder.Append(Baths[array[i]]);
50 |
51 | return builder.ToString();
52 | }
53 |
54 | public static byte[] ToBytes(this String hexString)
55 | {
56 | try
57 | {
58 | byte[] result = new byte[hexString.Length / 2];
59 |
60 | for (int index = 0; index < result.Length; index++)
61 | {
62 | string byteValue = hexString.Substring(index * 2, 2);
63 | result[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
64 | }
65 |
66 | return result;
67 | }
68 | catch (Exception)
69 | {
70 | Console.WriteLine("Invalid hex string: {0}", hexString);
71 | throw;
72 | }
73 | }
74 |
75 | public static string FormatHex(this byte[] buffer)
76 | {
77 | System.Text.StringBuilder sb = new System.Text.StringBuilder();
78 | sb.AppendFormat("Buffer dump, length: {0}{1}Index |---------------------------------------------| |--------------|{1}", buffer.Length, Environment.NewLine);
79 |
80 | int index = 0, i;
81 | string hex, data;
82 |
83 | while (index < buffer.Length)
84 | {
85 | hex = data = String.Empty;
86 |
87 | for (i = 0; i < 16 && index + i < buffer.Length; i++)
88 | {
89 | hex += buffer[index + i].ToString("x2") + " ";
90 |
91 | if (buffer[i + index] > 31 && buffer[i + index] < 127)
92 | data += (char)buffer[i + index];
93 | else
94 | data += ".";
95 | }
96 |
97 | while (i < 16)
98 | {
99 | hex += " ";
100 | i++;
101 | }
102 |
103 | sb.AppendFormat("{0} {1} {2}{3}", index.ToString("X5"), hex.ToUpper(), data, Environment.NewLine);
104 | index += 16;
105 | }
106 |
107 | sb.Append(" |---------------------------------------------| |--------------|");
108 |
109 | return sb.ToString();
110 | }
111 |
112 | public static void WriteScope(ref byte[] Data)
113 | {
114 | byte[] start_scope = new byte[2] { 0xAA, 0x55 };
115 | byte[] end_scope = new byte[2] { 0x55, 0xAA };
116 | byte[] buffer = new byte[Data.Length + 4];
117 | Buffer.BlockCopy(start_scope, 0, buffer, 0, 2);
118 | Buffer.BlockCopy(Data, 0, buffer, 2, Data.Length);
119 | Buffer.BlockCopy(end_scope, 0, buffer, Data.Length + 2, 2);
120 | Data = buffer;
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/LoginServer/Network/Client.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using LoginServer.Model.Account;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Net;
7 | using System.Net.Sockets;
8 | using System.Text;
9 | using System.Threading;
10 |
11 | namespace LoginServer.Network
12 | {
13 | public class Client
14 | {
15 | public EndPoint _address;
16 | public TcpClient _client;
17 | public NetworkStream _stream;
18 | private byte[] _buffer;
19 |
20 | public Account _Account;
21 |
22 | public Client(TcpClient client)
23 | {
24 | _client = client;
25 | _stream = client.GetStream();
26 | _address = client.Client.RemoteEndPoint;
27 |
28 | new Thread(new ThreadStart(BeginRead)).Start();
29 | }
30 |
31 | private void close()
32 | {
33 | ClientManager.GetInstance().RemoveClient(this);
34 | this._stream.Dispose();
35 | }
36 |
37 | private void BeginRead()
38 | {
39 | try
40 | {
41 | if (this._stream == null || !this._stream.CanRead)
42 | return;
43 |
44 | _buffer = new byte[1024];
45 | _stream.BeginRead(_buffer, 0, _buffer.Length, new AsyncCallback(OnReceiveCallback), (object)null);
46 | }
47 | catch (Exception ex)
48 | {
49 | Log.ErrorException("[Client]: BeginRead() Exception", ex);
50 | close();
51 | }
52 | }
53 |
54 | private void OnReceiveCallback(IAsyncResult ar)
55 | {
56 | int length = _stream.EndRead(ar);
57 | byte[] data = new byte[length];
58 | Buffer.BlockCopy(_buffer, 0, data, 0, length);
59 |
60 | if (data.Length >= 2)
61 | handlePacket(data);
62 |
63 | new Thread(new ThreadStart(BeginRead)).Start();
64 | }
65 |
66 | public void Send(byte[] bytes)
67 | {
68 | _stream = _client.GetStream();
69 | _stream.BeginWrite(bytes, 0, bytes.Length, WriteCallback, null);
70 | }
71 |
72 | public void SendPacket(ASendPacket packet)
73 | {
74 | packet._Client = this;
75 |
76 | if (!Opcode.Send.ContainsKey(packet.GetType()))
77 | {
78 | Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
79 | return;
80 | }
81 |
82 | try
83 | {
84 | packet.WriteH(Opcode.Send[packet.GetType()]); // opcode
85 | packet.WriteH(0); // packet len
86 | packet.Write();
87 |
88 | byte[] Data = packet.ToByteArray();
89 | BitConverter.GetBytes((short)(Data.Length - 4)).CopyTo(Data, 2);
90 |
91 | //if(Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
92 | _stream = _client.GetStream();
93 | _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
94 | }
95 | catch (Exception ex)
96 | {
97 | Log.Warn("Can't send GS packet: {0}", GetType().Name);
98 | Log.WarnException("GSASendPacket", ex);
99 | return;
100 | }
101 | }
102 |
103 | private void WriteCallback(IAsyncResult result)
104 | {
105 | _stream.EndWrite(result);
106 | }
107 |
108 | private void handlePacket(byte[] Data)
109 | {
110 | Log.Debug("Recv Handle: {0}", Data.FormatHex());
111 | short opcode = BitConverter.ToInt16(new byte[2] { Data[0], Data[1] }, 0);
112 |
113 | if (Opcode.Recv.ContainsKey(opcode))
114 | {
115 | ((ARecvPacket)Activator.CreateInstance(Opcode.Recv[opcode])).execute(this, Data);
116 | }
117 | else
118 | {
119 | string opCodeLittleEndianHex = BitConverter.GetBytes(opcode).ToHex();
120 | Log.Debug("Unknown Opcode: 0x{0}{1} [{2}]",
121 | opCodeLittleEndianHex.Substring(2),
122 | opCodeLittleEndianHex.Substring(0, 2),
123 | Data.Length);
124 |
125 | Log.Debug("Data:\n{0}", Data.FormatHex());
126 | }
127 | }
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/GameServer/Network/ARecvPacket.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using System;
3 | using System.Text;
4 |
5 | namespace GameServer.Network
6 | {
7 | public abstract class ARecvPacket
8 | {
9 | private byte[] _buffer;
10 | private int _offset;
11 | protected Client _Client;
12 |
13 | protected internal Client GetClient()
14 | {
15 | return _Client;
16 | }
17 |
18 | protected internal byte[] GetBuffer()
19 | {
20 | return this._buffer;
21 | }
22 |
23 | protected internal void execute(Client Client, byte[] buffer)
24 | {
25 | _Client = Client;
26 | _buffer = buffer;
27 | _offset = 8;
28 | Read();
29 | Run();
30 | }
31 |
32 | protected internal int ReadD()
33 | {
34 | int num = BitConverter.ToInt32(this._buffer, this._offset);
35 | this._offset += 4;
36 | return num;
37 | }
38 |
39 | protected internal byte ReadC()
40 | {
41 | byte num = this._buffer[this._offset];
42 | ++this._offset;
43 | return num;
44 | }
45 |
46 | protected internal byte[] ReadB(int Length)
47 | {
48 | byte[] numArray = new byte[Length];
49 | Array.Copy((Array)this._buffer, this._offset, (Array)numArray, 0, Length);
50 | this._offset += Length;
51 | return numArray;
52 | }
53 |
54 | protected internal short ReadH()
55 | {
56 | short num = BitConverter.ToInt16(this._buffer, this._offset);
57 | this._offset += 2;
58 | return num;
59 | }
60 |
61 | protected internal double ReadF()
62 | {
63 | double num = BitConverter.ToDouble(this._buffer, this._offset);
64 | this._offset += 8;
65 | return num;
66 | }
67 |
68 | protected internal long ReadQ()
69 | {
70 | long num = BitConverter.ToInt64(this._buffer, this._offset);
71 | this._offset += 8;
72 | return num;
73 | }
74 |
75 | protected internal string ReadS(int Length)
76 | {
77 | string str = "";
78 | try
79 | {
80 | str = Encoding.Default.GetString(this._buffer, this._offset, Length);
81 | int length = str.IndexOf(char.MinValue);
82 | if (length != -1)
83 | str = str.Substring(0, length);
84 | this._offset += Length;
85 | }
86 | catch (Exception ex)
87 | {
88 | Log.ErrorException("while reading string from packet", ex);
89 | }
90 | return str;
91 | }
92 |
93 | protected internal string ReadS()
94 | {
95 | string str = "";
96 | try
97 | {
98 | int len = ReadH();
99 | str = ReadS(len); ;
100 | }
101 | catch (Exception ex)
102 | {
103 | Log.ErrorException("while reading string from packet", ex);
104 | }
105 | return str;
106 | }
107 |
108 | protected internal void Ignore(int in_offset)
109 | {
110 | this._offset = this._offset + in_offset;
111 | Log.Trace("Ignore {0} bytes", in_offset);
112 | }
113 |
114 | protected internal int PacketLength
115 | {
116 | get
117 | {
118 | return BitConverter.ToInt16(new byte[2] { _buffer[0], _buffer[1] }, 0);
119 | }
120 | }
121 |
122 | protected internal int SessionId
123 | {
124 | get
125 | {
126 | return BitConverter.ToInt16(new byte[2] { _buffer[2], _buffer[3] }, 0);
127 | }
128 | }
129 |
130 | protected internal int Opcode
131 | {
132 | get
133 | {
134 | return BitConverter.ToInt16(new byte[2] { _buffer[4], _buffer[5] }, 0);
135 | }
136 | }
137 |
138 | protected internal int DataLength
139 | {
140 | get
141 | {
142 | return BitConverter.ToInt16(new byte[2] { _buffer[6], _buffer[7] }, 0);
143 | }
144 | }
145 |
146 | protected internal abstract void Read();
147 |
148 | protected internal abstract void Run();
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/LoginServer/Network/GameServer/GSClient.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using LoginServer.Config;
3 | using System;
4 | using System.Net;
5 | using System.Net.Sockets;
6 | using System.Text;
7 | using System.Threading;
8 |
9 | namespace LoginServer.Network.GameServer
10 | {
11 | public class GSClient
12 | {
13 | public EndPoint _address;
14 | public TcpClient _client;
15 | public NetworkStream _stream;
16 | private byte[] _buffer;
17 |
18 | public GSClient(TcpClient client)
19 | {
20 | _client = client;
21 | _stream = client.GetStream();
22 | _address = client.Client.RemoteEndPoint;
23 |
24 | new Thread(new ThreadStart(BeginRead)).Start();
25 | }
26 |
27 | private void close()
28 | {
29 | GameServerManager.GetInstance().RemoveClient(this);
30 | this._stream.Dispose();
31 | }
32 |
33 | private void BeginRead()
34 | {
35 | try
36 | {
37 | if (this._stream == null || !this._stream.CanRead)
38 | return;
39 |
40 | _buffer = new byte[1024];
41 | _stream.BeginRead(_buffer, 0, _buffer.Length, new AsyncCallback(OnReceiveCallback), (object)null);
42 | }
43 | catch (Exception ex)
44 | {
45 | Log.ErrorException("[GSClient]: BeginRead() Exception", ex);
46 | close();
47 | }
48 | }
49 |
50 | private void OnReceiveCallback(IAsyncResult ar)
51 | {
52 | try
53 | {
54 | int length = _stream.EndRead(ar);
55 | byte[] data = new byte[length];
56 | Buffer.BlockCopy(_buffer, 0, data, 0, length);
57 |
58 | if (data.Length >= 2)
59 | handlePacket(data);
60 |
61 | new Thread(new ThreadStart(BeginRead)).Start();
62 | }
63 | catch
64 | {
65 | GameServerManager.GetInstance().RemoveClient(this);
66 | Log.Error("Lost connection from gameserver");
67 | }
68 | }
69 |
70 | public void Send(byte[] bytes)
71 | {
72 | _stream = _client.GetStream();
73 | _stream.BeginWrite(bytes, 0, bytes.Length, WriteCallback, null);
74 | }
75 |
76 | public void SendPacket(GSASendPacket packet)
77 | {
78 | packet._Client = this;
79 |
80 | if (!GSOpcode.Send.ContainsKey(packet.GetType()))
81 | {
82 | Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
83 | return;
84 | }
85 |
86 | try
87 | {
88 | packet.WriteH(GSOpcode.Send[packet.GetType()]); // opcode
89 | packet.WriteH(0); // packet len
90 | packet.Write();
91 |
92 | byte[] Data = packet.ToByteArray();
93 | BitConverter.GetBytes((short)(Data.Length - 4)).CopyTo(Data, 2);
94 |
95 | //if(Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
96 | _stream = _client.GetStream();
97 | _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
98 | }
99 | catch (Exception ex)
100 | {
101 | Log.Warn("Can't send GS packet: {0}", GetType().Name);
102 | Log.WarnException("GSASendPacket", ex);
103 | return;
104 | }
105 | }
106 |
107 | private void WriteCallback(IAsyncResult result)
108 | {
109 | _stream.EndWrite(result);
110 | }
111 |
112 | private void handlePacket(byte[] Data)
113 | {
114 | //Log.Debug("Recv Handle: {0}", Data.FormatHex());
115 |
116 | short opcode = BitConverter.ToInt16(new byte[2] { Data[0], Data[1] }, 0);
117 |
118 | if (GSOpcode.Recv.ContainsKey(opcode))
119 | {
120 | ((GSARecvPacket)Activator.CreateInstance(GSOpcode.Recv[opcode])).execute(this, Data);
121 | }
122 | else
123 | {
124 | string opCodeLittleEndianHex = BitConverter.GetBytes(opcode).ToHex();
125 | Log.Debug("Unknown GS Opcode: 0x{0}{1} [{2}]",
126 | opCodeLittleEndianHex.Substring(2),
127 | opCodeLittleEndianHex.Substring(0, 2),
128 | Data.Length);
129 |
130 | Log.Debug("Data:\n{0}", Data.FormatHex());
131 | }
132 | }
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/GameServer/Network/LoginServer/LSClient.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using GameServer.Config;
3 | using GameServer.Network.LoginServer.Send;
4 | using System;
5 | using System.Net.Sockets;
6 | using System.Text;
7 | using System.Threading;
8 |
9 | namespace GameServer.Network.LoginServer
10 | {
11 | public class LSClient
12 | {
13 | private static LSClient Instance;
14 |
15 | public TcpClient _client;
16 | public NetworkStream _stream;
17 | private byte[] _buffer;
18 | private int failedConnectionCount;
19 |
20 | public static LSClient GetInstance()
21 | {
22 | return (Instance != null) ? Instance : Instance = Instance = new LSClient();
23 | }
24 |
25 | public LSClient()
26 | {
27 | LSOpcode.Init();
28 | _client = new TcpClient();
29 | _client.BeginConnect(Configuration.Network.LoginIp, Configuration.Network.LoginPort, ConnectCallback, null);
30 | }
31 |
32 | private void ConnectCallback(IAsyncResult result)
33 | {
34 | try
35 | {
36 | _client.EndConnect(result);
37 |
38 | SendPacket(new GSReqRegistServer());
39 | }
40 | catch
41 | {
42 | Interlocked.Increment(ref failedConnectionCount);
43 | if (failedConnectionCount >= 5)
44 | return; //connection has failed overall.
45 | }
46 |
47 | NetworkStream networkStream = _client.GetStream();
48 | _buffer = new byte[_client.ReceiveBufferSize];
49 | networkStream.BeginRead(_buffer, 0, _buffer.Length, ReadCallback, _buffer);
50 | }
51 |
52 | private void ReadCallback(IAsyncResult result)
53 | {
54 | int length = 0;
55 | try
56 | {
57 | _stream = _client.GetStream();
58 | if (_stream != null)
59 | length = _stream.EndRead(result);
60 | }
61 | catch
62 | {
63 | Log.Error("Lost connection from loginserver");
64 | return;
65 | }
66 |
67 | if (length == 0)
68 | {
69 | return;
70 | }
71 |
72 | byte[] data = new byte[length];
73 | Buffer.BlockCopy(_buffer, 0, data, 0, length);
74 |
75 | HandlePacket(data);
76 |
77 | _stream.BeginRead(_buffer, 0, _buffer.Length, ReadCallback, _buffer);
78 | }
79 |
80 | public void Send(byte[] bytes)
81 | {
82 | _stream = _client.GetStream();
83 | _stream.BeginWrite(bytes, 0, bytes.Length, WriteCallback, null);
84 | }
85 |
86 | public void SendPacket(LSASendPacket packet)
87 | {
88 | packet._Client = this;
89 |
90 | if (!LSOpcode.Send.ContainsKey(packet.GetType()))
91 | {
92 | Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
93 | return;
94 | }
95 |
96 | try
97 | {
98 | packet.WriteH(LSOpcode.Send[packet.GetType()]); // opcode
99 | packet.WriteH(0); // packet len
100 | packet.Write();
101 |
102 | byte[] Data = packet.ToByteArray();
103 | BitConverter.GetBytes((short)(Data.Length - 4)).CopyTo(Data, 2);
104 |
105 | //if (Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
106 | _stream = _client.GetStream();
107 | _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
108 | }
109 | catch (Exception ex)
110 | {
111 | Log.Warn("Can't send GS packet: {0}", GetType().Name);
112 | Log.WarnException("GSASendPacket", ex);
113 | return;
114 | }
115 | }
116 |
117 | private void WriteCallback(IAsyncResult result)
118 | {
119 | _stream.EndWrite(result);
120 | }
121 |
122 | private void HandlePacket(byte[] Data)
123 | {
124 | //Log.Debug("Recv Handle: {0}", _buffer.FormatHex());
125 |
126 | short opcode = BitConverter.ToInt16(new byte[2] { Data[0], Data[1] }, 0);
127 |
128 | if (LSOpcode.Recv.ContainsKey(opcode))
129 | {
130 | ((LSARecvPacket)Activator.CreateInstance(LSOpcode.Recv[opcode])).execute(this, Data);
131 | }
132 | else
133 | {
134 | string opCodeLittleEndianHex = BitConverter.GetBytes(opcode).ToHex();
135 | Log.Debug("Unknown Opcode: 0x{0}{1} [{2}]",
136 | opCodeLittleEndianHex.Substring(2),
137 | opCodeLittleEndianHex.Substring(0, 2),
138 | Data.Length);
139 |
140 | Log.Debug("Data:\n{0}", Data.FormatHex());
141 | }
142 | }
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/GameServer/Network/ASendPacket.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using GameServer.Config;
3 | using GameServer.Model.Item;
4 | using System;
5 | using System.IO;
6 | using System.Text;
7 |
8 | namespace GameServer.Network
9 | {
10 | public abstract class ASendPacket
11 | {
12 | private MemoryStream mstream = new MemoryStream();
13 |
14 | public Client _Client;
15 |
16 | public void Send(Client c)
17 | {
18 | _Client = c;
19 |
20 | if (!Opcode.Send.ContainsKey(GetType()))
21 | {
22 | Log.Warn("UNKNOWN GS packet opcode: {0}", GetType().Name);
23 | return;
24 | }
25 |
26 | try
27 | {
28 | WriteH(0); // packet len
29 | WriteH(_Client.SessID); // session
30 | WriteH(Opcode.Send[GetType()]); // opcode
31 | WriteH(0); // data len
32 | Write();
33 |
34 | byte[] Data = ToByteArray();
35 | BitConverter.GetBytes((short)(Data.Length - 2)).CopyTo(Data, 0);
36 | BitConverter.GetBytes((short)(Data.Length - 8)).CopyTo(Data, 6);
37 |
38 | if (Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
39 |
40 | Funcs.WriteScope(ref Data);
41 | _Client.Send(Data);
42 | }
43 | catch (Exception ex)
44 | {
45 | Log.Warn("Can't send packet: {0}", GetType().Name);
46 | Log.WarnException("ASendPacket", ex);
47 | return;
48 | }
49 | }
50 |
51 | public long Length
52 | {
53 | get
54 | {
55 | return this.mstream.Length;
56 | }
57 | }
58 |
59 | protected internal void WriteB(byte[] value)
60 | {
61 | this.mstream.Write(value, 0, value.Length);
62 | }
63 |
64 | protected internal void WriteD(int value)
65 | {
66 | WriteB(BitConverter.GetBytes(value));
67 | }
68 |
69 | protected internal void WriteH(short val)
70 | {
71 | WriteB(BitConverter.GetBytes(val));
72 | }
73 |
74 | protected internal void WriteH(int val)
75 | {
76 | WriteB(BitConverter.GetBytes((short)val));
77 | }
78 |
79 | protected internal void WriteC(byte value)
80 | {
81 | this.mstream.WriteByte(value);
82 | }
83 |
84 | protected internal void WriteC(int value)
85 | {
86 | this.mstream.WriteByte((byte)value);
87 | }
88 |
89 | protected internal void WriteF(double value)
90 | {
91 | WriteB(BitConverter.GetBytes(value));
92 | }
93 |
94 | protected internal void WriteQ(long value)
95 | {
96 | WriteB(BitConverter.GetBytes(value));
97 | }
98 |
99 | protected internal void WriteS(string value)
100 | {
101 | if (value == null)
102 | return;
103 |
104 | WriteH((short)value.Length);
105 | WriteB(Encoding.Default.GetBytes(value));
106 | }
107 |
108 | protected internal void WriteS(string name, int count)
109 | {
110 | if (name == null)
111 | return;
112 |
113 | WriteB(Encoding.Default.GetBytes(name));
114 | WriteB(new byte[count - name.Length]);
115 | }
116 |
117 | protected void WriteItemInfo(StorageItem item)
118 | {
119 | /*if (item != null)
120 | {
121 | WriteQ(item.UID);
122 | WriteQ(item.ItemId);
123 | WriteD(item.Amount); // Amount
124 | WriteD(item.Magic0); // FLD_MAGIC0
125 | WriteD(item.Magic1); // FLD_MAGIC1
126 | WriteD(item.Magic2); // FLD_MAGIC2
127 | WriteD(item.Magic3); // FLD_MAGIC3
128 | WriteD(item.Magic4); // FLD_MAGIC4
129 | WriteH(0);
130 | WriteH(0); // (IsBlue == true ? 1 : 0)
131 | WriteH(item.BonusMagic1); // BonusMagic1
132 | WriteH(item.BonusMagic2); // BonusMagic2
133 | WriteH(item.BonusMagic3); // BonusMagic3
134 | WriteH(item.BonusMagic4); // BonusMagic4
135 | WriteH(item.BonusMagic5); // BonusMagic5
136 | WriteD(0);
137 | WriteD((item.LimitTime > 0 ? 1 : 0));
138 | WriteD(item.LimitTime);
139 | WriteH(item.Upgrade);
140 | WriteH(item.ItemTemplate.Category); // ItemType
141 | WriteH(0); // 0
142 | WriteH(0);
143 | WriteQ(0);
144 | WriteB(new byte[6]);
145 | }
146 | else*/
147 | WriteB(new byte[88]);
148 | }
149 |
150 | public byte[] ToByteArray()
151 | {
152 | return this.mstream.ToArray();
153 | }
154 |
155 | protected internal abstract void Write();
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/GameServer/Network/Client.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using GameServer.Config;
3 | using GameServer.Model.Account;
4 | using GameServer.Model.Character;
5 | using System;
6 | using System.Net;
7 | using System.Net.Sockets;
8 | using System.Threading;
9 |
10 | namespace GameServer.Network
11 | {
12 | public class Client
13 | {
14 | public EndPoint _address;
15 | public TcpClient _client;
16 | public NetworkStream _stream;
17 | private byte[] _buffer;
18 |
19 | public short SessID;
20 | public Account _Account;
21 | public Character _Char;
22 |
23 | public Client(TcpClient client)
24 | {
25 | _client = client;
26 | _stream = client.GetStream();
27 | _address = client.Client.RemoteEndPoint;
28 |
29 | new Thread(new ThreadStart(BeginRead)).Start();
30 | }
31 |
32 | private void close()
33 | {
34 | ClientManager.GetInstance().RemoveClient(this);
35 | this._stream.Dispose();
36 | }
37 |
38 | private void BeginRead()
39 | {
40 | try
41 | {
42 | if (this._stream == null || !this._stream.CanRead)
43 | return;
44 |
45 | _buffer = new byte[1024];
46 | _stream.BeginRead(_buffer, 0, _buffer.Length, new AsyncCallback(OnReceiveCallback), (object)null);
47 | }
48 | catch (Exception ex)
49 | {
50 | Log.ErrorException("[Client]: BeginRead() Exception", ex);
51 | close();
52 | }
53 | }
54 |
55 | private void OnReceiveCallback(IAsyncResult ar)
56 | {
57 | try
58 | {
59 | int length = _stream.EndRead(ar);
60 |
61 | byte[] data = new byte[length - 4];
62 | Buffer.BlockCopy(_buffer, 2, data, 0, length - 4);
63 |
64 | string bytesString = BitConverter.ToString(data).Replace("-", "");
65 | string[] delimiters = new string[] { "55AAAA55" };
66 | string[] strArray = bytesString.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
67 |
68 | foreach (string str in strArray)
69 | {
70 | handlePacket(str.ToBytes());
71 | }
72 | }
73 | catch(Exception ex)
74 | {
75 | Log.Warn("Client Disconnected");
76 | //Log.WarnException("OnReceiveCallback", ex);
77 | close();
78 | }
79 | finally
80 | {
81 | new Thread(new ThreadStart(BeginRead)).Start();
82 | }
83 | }
84 |
85 | public void Send(byte[] bytes)
86 | {
87 | _stream = _client.GetStream();
88 | _stream.BeginWrite(bytes, 0, bytes.Length, WriteCallback, null);
89 | }
90 |
91 | public void SendPacket(ASendPacket packet)
92 | {
93 | packet._Client = this;
94 |
95 | if (!Opcode.Send.ContainsKey(packet.GetType()))
96 | {
97 | Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
98 | return;
99 | }
100 |
101 | try
102 | {
103 | packet.WriteH(0); // packet len
104 | packet.WriteH(SessID); // session
105 | packet.WriteH(Opcode.Send[packet.GetType()]); // opcode
106 | packet.WriteH(0); // data len
107 | packet.Write();
108 |
109 | byte[] Data = packet.ToByteArray();
110 | BitConverter.GetBytes((short)(Data.Length - 2)).CopyTo(Data, 0);
111 | BitConverter.GetBytes((short)(Data.Length - 8)).CopyTo(Data, 6);
112 |
113 | if (Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
114 |
115 | Funcs.WriteScope(ref Data);
116 | _stream = _client.GetStream();
117 | _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
118 | }
119 | catch (Exception ex)
120 | {
121 | Log.Warn("Can't send packet: {0}", GetType().Name);
122 | Log.WarnException("ASendPacket", ex);
123 | return;
124 | }
125 | }
126 |
127 | private void WriteCallback(IAsyncResult result)
128 | {
129 | _stream.EndWrite(result);
130 | }
131 |
132 | private void handlePacket(byte[] Data)
133 | {
134 | if (Configuration.Setting.Debug) Log.Debug("Recv: {0}", Data.FormatHex());
135 |
136 | short opcode = BitConverter.ToInt16(new byte[2] { Data[4], Data[5] }, 0);
137 |
138 | if (Opcode.Recv.ContainsKey(opcode))
139 | {
140 | ((ARecvPacket)Activator.CreateInstance(Opcode.Recv[opcode])).execute(this, Data);
141 | }
142 | else
143 | {
144 | string opCodeLittleEndianHex = BitConverter.GetBytes(opcode).ToHex();
145 | Log.Warn("Unknown Opcode: 0x{0}{1} [{2}]",
146 | opCodeLittleEndianHex.Substring(2),
147 | opCodeLittleEndianHex.Substring(0, 2),
148 | Data.Length);
149 |
150 | Log.Warn("Data:\n{0}", Data.FormatHex());
151 | }
152 | }
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/LoginServer/LoginServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {D2C7CE20-856E-4524-B246-B17BE603BB49}
8 | Exe
9 | Properties
10 | LoginServer
11 | LoginServer
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\packages\mongocsharpdriver.1.9.0\lib\net35\MongoDB.Bson.dll
37 |
38 |
39 | ..\packages\mongocsharpdriver.1.9.0\lib\net35\MongoDB.Driver.dll
40 |
41 |
42 | ..\packages\Trove.Nini.1.1.0.0\lib\net20\Nini.dll
43 |
44 |
45 | ..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | PreserveNewest
91 |
92 |
93 | PreserveNewest
94 |
95 |
96 | PreserveNewest
97 |
98 |
99 |
100 |
101 |
102 | {2cc06d57-6a68-473d-a7ed-d19ca8381b57}
103 | Common
104 |
105 |
106 |
107 |
108 |
115 |
--------------------------------------------------------------------------------
/GameServer/GameServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {05AD4BBF-5D1F-4AD7-878E-A634732D29AC}
8 | Exe
9 | Properties
10 | GameServer
11 | GameServer
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\packages\mongocsharpdriver.1.9.0\lib\net35\MongoDB.Bson.dll
37 |
38 |
39 | ..\packages\mongocsharpdriver.1.9.0\lib\net35\MongoDB.Driver.dll
40 |
41 |
42 | ..\packages\Trove.Nini.1.1.0.0\lib\net20\Nini.dll
43 |
44 |
45 | ..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 | PreserveNewest
121 |
122 |
123 | PreserveNewest
124 |
125 |
126 | PreserveNewest
127 |
128 |
129 | PreserveNewest
130 |
131 |
132 |
133 |
134 |
135 | {2cc06d57-6a68-473d-a7ed-d19ca8381b57}
136 | Common
137 |
138 |
139 |
140 |
141 |
142 |
143 |
150 |
--------------------------------------------------------------------------------
/GameServer/Service/StatsService.cs:
--------------------------------------------------------------------------------
1 | using Common.Utilities;
2 | using GameServer.DataHolder;
3 | using GameServer.Model.Character;
4 | using GameServer.Model.Creature;
5 | using System.Collections.Generic;
6 |
7 | namespace GameServer.Service
8 | {
9 | public class StatsService
10 | {
11 | private static StatsService Instance;
12 |
13 | public static Dictionary> CharacterStats = new Dictionary>();
14 |
15 | public static int MaxLevel = 130;
16 |
17 | public StatsService()
18 | {
19 | for (int i = 0; i < Data.Stats.Count; i++)
20 | {
21 | CharacterStats.Add((CharacterClass)i + 1, new Dictionary());
22 |
23 | CreatureBaseStats firstLevelStats = Data.Stats[i];
24 |
25 | for (int j = 1; j < MaxLevel; j++)
26 | {
27 | CreatureBaseStats stats = firstLevelStats.Clone();
28 |
29 | switch (stats.PlayerClass)
30 | {
31 | case CharacterClass.Blademan:
32 | stats.HpBase += (j * 12);
33 | stats.MpBase += (j * 2);
34 | stats.Spirit += j;
35 | stats.Strength += j + ((j % 2 == 0) ? 2 : 1);
36 | stats.Stamina += j + ((j % 2 == 0) ? 2 : 1);
37 | stats.Dexterity += j;
38 | stats.Attack += j + ((j % 2 == 0) ? 2 : 1);
39 | stats.Defense += j;
40 | stats.Accuracy += j;
41 | stats.Dodge += j;
42 | break;
43 | case CharacterClass.Swordman:
44 | stats.HpBase += (j * 12);
45 | stats.MpBase += (j * 2);
46 | stats.Spirit += j + ((j % 2 == 0) ? 2 : 1);
47 | stats.Strength += j;
48 | stats.Stamina += (j * 2);
49 | stats.Dexterity += (j * 2);
50 | stats.Attack += (j * 2);
51 | stats.Defense += j;
52 | stats.Accuracy += (j * 2);
53 | stats.Dodge += (j * 2);
54 | break;
55 | case CharacterClass.Spearman:
56 | stats.HpBase += (j * 12);
57 | stats.MpBase += (j * 2);
58 | stats.Spirit += j;
59 | stats.Strength += j;
60 | stats.Stamina += (j * 3);
61 | stats.Dexterity += j;
62 | stats.Attack += (j * 3);
63 | stats.Defense += j;
64 | stats.Accuracy += j;
65 | stats.Dodge += j;
66 | break;
67 | case CharacterClass.Bowman:
68 | stats.HpBase += (j * 12);
69 | stats.MpBase += (j * 2);
70 | stats.Spirit += (j * 2);
71 | stats.Strength += j;
72 | stats.Stamina += j + ((j % 2 == 0) ? 2 : 3);
73 | stats.Dexterity += (j * 3);
74 | stats.Attack += j + ((j % 2 == 0) ? 2 : 3);
75 | stats.Defense += j;
76 | stats.Accuracy += (j * 3);
77 | stats.Dodge += (j * 3);
78 | break;
79 | case CharacterClass.Medic:
80 | stats.HpBase += (j * 7);
81 | stats.MpBase += (j * 6);
82 | stats.Spirit += (j * 3);
83 | stats.Strength += (j * 2);
84 | stats.Stamina += (j * 2);
85 | stats.Dexterity += j;
86 | stats.Attack += (j * 2);
87 | stats.Defense += j;
88 | stats.Accuracy += j;
89 | stats.Dodge += j;
90 | break;
91 | case CharacterClass.Ninja:
92 | stats.HpBase += (j * 10);
93 | stats.MpBase += (j * 4);
94 | stats.Spirit += (j * 2);
95 | stats.Strength += (j * 2);
96 | stats.Stamina += j + ((j % 2 == 0) ? 1 : 2);
97 | stats.Dexterity += (j * 3);
98 | stats.Attack += j + ((j % 2 == 0) ? 2 : 3);
99 | stats.Defense += j;
100 | stats.Accuracy += j;
101 | stats.Dodge += (j * 2);
102 | break;
103 | case CharacterClass.Busker: // Temp copy from medic
104 | stats.HpBase += (j * 7);
105 | stats.MpBase += (j * 6);
106 | stats.Spirit += (j * 3);
107 | stats.Strength += (j * 2);
108 | stats.Stamina += (j * 2);
109 | stats.Dexterity += j;
110 | stats.Attack += (j * 2);
111 | stats.Defense += j;
112 | stats.Accuracy += j;
113 | stats.Dodge += j;
114 | break;
115 | case CharacterClass.Hanbi:
116 | stats.HpBase += (j * 12);
117 | stats.MpBase += (j * 2);
118 | stats.Spirit += j;
119 | stats.Strength += j + ((j % 2 == 0) ? 1 : 2);
120 | stats.Stamina += j + ((j % 2 == 0) ? 1 : 2);
121 | stats.Dexterity += j;
122 | stats.Attack += j + ((j % 2 == 0) ? 1 : 2);
123 | stats.Defense += j + ((j % 2 == 0) ? 1 : 2);
124 | stats.Accuracy += j + ((j % 4 == 0) ? 1 : 2);
125 | stats.Dodge += j + ((j % 2 == 0) ? 1 : 2);
126 | break;
127 | }
128 |
129 | stats.SpBase += (j * 10);
130 |
131 | CharacterStats[(CharacterClass)i + 1].Add(j, stats);
132 | }
133 | }
134 | }
135 |
136 | public CreatureBaseStats InitStats(Creature creature)
137 | {
138 | Character character = creature as Character;
139 | if (character != null)
140 | return GetBaseStats(character).Clone();
141 |
142 | Log.Error("StatsService: Unknown type: {0}.", creature.GetType().Name);
143 | return new CreatureBaseStats();
144 | }
145 |
146 | public CreatureBaseStats GetBaseStats(Character character)
147 | {
148 | return CharacterStats[character.Class][character.Level];
149 | }
150 |
151 | public void UpdateStats(Creature creature)
152 | {
153 | Character character = creature as Character;
154 | if (character != null)
155 | {
156 | UpdatePlayerStats(character);
157 | return;
158 | }
159 |
160 | Log.Error("StatsService: Unknown type: {0}.", creature.GetType().Name);
161 | }
162 |
163 | private void UpdatePlayerStats(Character character)
164 | {
165 | CreatureBaseStats baseStats = GetBaseStats(character);
166 | baseStats.CopyTo(character.GameStats);
167 |
168 | int itemsAttack = 0,
169 | itemsDefense = 0;
170 |
171 | /*lock (character.Inventory.ItemsLock)
172 | {
173 | foreach (var item in player.Inventory.EquipItems.Values)
174 | {
175 | if (item == null)
176 | continue;
177 |
178 | ItemTemplate itemTemplate = item.ItemTemplate;
179 |
180 | if (itemTemplate != null)
181 | {
182 | itemsAttack += itemTemplate.MinAttack + ((itemTemplate.Category == 3) ? (item.Upgrade * 5) : 0);
183 | itemsDefense += itemTemplate.Defense + ((itemTemplate.Category == 1) ? (item.Upgrade * 5) : 0);
184 | }
185 | }
186 | }*/
187 |
188 | character.GameStats.Attack = (int)(baseStats.Attack + (0.03f * baseStats.Strength + 3) + itemsAttack);
189 | character.GameStats.Defense = (int)(baseStats.Defense + (0.01f * baseStats.Stamina + 0.5) + itemsDefense);
190 |
191 | //character.EffectsImpact.ResetChanges(character);
192 | //character.EffectsImpact.ApplyChanges(character.GameStats);
193 |
194 | //new SpPlayerStats(player).Send(player);
195 | //new SpPlayerHpMpSp(player).Send(player);
196 | }
197 |
198 |
199 | public static StatsService GetInstance()
200 | {
201 | return (Instance != null) ? Instance : Instance = new StatsService();
202 | }
203 | }
204 | }
205 |
--------------------------------------------------------------------------------