diff --git a/Database/ServerData.sdf b/Database/ServerData.sdf
index a9104f9..ad457a1 100644
Binary files a/Database/ServerData.sdf and b/Database/ServerData.sdf differ
diff --git a/Database/ServerData.sdf.fucked b/Database/ServerData.sdf.fucked
new file mode 100644
index 0000000..d8d368e
Binary files /dev/null and b/Database/ServerData.sdf.fucked differ
diff --git a/SocketService.Core/SocketService.Core.csproj b/SocketService.Core/SocketService.Core.csproj
index 7f4201f..29e6bff 100644
--- a/SocketService.Core/SocketService.Core.csproj
+++ b/SocketService.Core/SocketService.Core.csproj
@@ -88,9 +88,6 @@
ServerDataModel.edmx
-
- Component
-
@@ -98,7 +95,7 @@
-
+
{93FD4F32-5214-40E3-8E36-5B4E354F10C4}
SocketService.Client.Core
diff --git a/SocketService.Framework/SocketServiceBase.cs b/SocketService.Framework/SocketServiceBase.cs
new file mode 100644
index 0000000..7736be4
--- /dev/null
+++ b/SocketService.Framework/SocketServiceBase.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration.Install;
+using System.Linq;
+using System.Reflection;
+using System.ServiceProcess;
+using System.Text;
+using System.Threading;
+using log4net;
+
+namespace SocketService.Framework
+{
+ public class SocketServiceBase : ServiceBase
+ {
+ protected static ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+ public SocketServiceBase()
+ {
+ CanStop = true;
+ CanPauseAndContinue = false;
+ AutoLog = true;
+ RunAsService = true;
+ }
+
+ public bool RunAsService { get; set; }
+
+ ///
+ /// Override in subclasses to start your application code. The code will automatically
+ /// be started as either a service or an application depending on the RunAsService property.
+ ///
+ public virtual void StartService() { }
+
+ ///
+ /// APSServiceBase default implementation for OnStart. This will only be called if RunAsService is set to true.
+ /// Implementers should not override this method. Instead, they should put all service start code in StartService.
+ /// The APSServiceBase will handle starting and stopping appropriately depending on whether RunAsService is set or not.
+ ///
+ ///
+ protected override void OnStart(string[] args)
+ {
+ var thread = new Thread(StartService) { Name = "ServiceThread", IsBackground = false};
+ thread.Start();
+ }
+
+ ///
+ /// Override in subclasses to stop your application code. This will only be called if RunAsService is true.
+ ///
+ public virtual void StopService() { }
+
+ ///
+ /// APSServiceBase default implementation for OnStop. This will only be called if RunAsService is set to true.
+ /// Implementers should not override this method. Instead, they should put all service shutdown code in StopService.
+ /// The APSServiceBase will handle starting and stopping appropriately depending on whether RunAsService is set or not.
+ ///
+ protected override void OnStop()
+ {
+ StopService();
+ }
+
+ public void Run()
+ {
+ // Set working directory to application directory.
+ // Otherwise Windows/System32 is used.
+ Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
+
+ // We must start the server appropriately depending on whether we are a service or not.
+ if (RunAsService)
+ {
+ Run(this);
+ }
+ else
+ {
+ StartService();
+ }
+ }
+ }
+}
diff --git a/SocketService/Command/GetCentralAuthorityCommand.cs b/SocketService/Command/GetCentralAuthorityCommand.cs
index 2317374..d68f05e 100644
--- a/SocketService/Command/GetCentralAuthorityCommand.cs
+++ b/SocketService/Command/GetCentralAuthorityCommand.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using SocketService.Core.Crypto;
using SocketService.Core.Messaging;
using SocketService.Net.Client;
diff --git a/SocketService/Command/GetCentralAuthorityCommand.cs.orig b/SocketService/Command/GetCentralAuthorityCommand.cs.orig
new file mode 100644
index 0000000..b3225e3
--- /dev/null
+++ b/SocketService/Command/GetCentralAuthorityCommand.cs.orig
@@ -0,0 +1,35 @@
+using System;
+<<<<<<< Updated upstream
+using SocketService.Core.Crypto;
+using SocketService.Core.Messaging;
+=======
+using System.Linq;
+using SocketService.Framework.Messaging;
+using SocketService.Crypto;
+>>>>>>> Stashed changes
+using SocketService.Net.Client;
+
+namespace SocketService.Command
+{
+ [Serializable]
+ public class GetCentralAuthorityCommand : BaseMessageHandler
+ {
+ private readonly Guid _clientId;
+ public GetCentralAuthorityCommand(Guid clientId)
+ {
+ _clientId = clientId;
+ }
+
+ public override void Execute()
+ {
+ var ca = new CentralAuthority(CAKeyProtocol.DH64);
+
+ ClientConnection connection =
+ ConnectionRepository.Instance.Query(c => c.ClientId == _clientId).FirstOrDefault();
+ if (connection == null) return;
+
+ connection.SecureKeyProvider = ca.GetProvider();
+ MSMQQueueWrapper.QueueCommand(new SendObjectCommand(_clientId, ca));
+ }
+ }
+}
diff --git a/SocketService/Command/LogoutUserCommand.cs b/SocketService/Command/LogoutUserCommand.cs
index 4d637b6..7e78c5e 100644
--- a/SocketService/Command/LogoutUserCommand.cs
+++ b/SocketService/Command/LogoutUserCommand.cs
@@ -1,10 +1,8 @@
using System;
-using System.Collections.Generic;
using System.Linq;
using SocketService.Actions;
using SocketService.Core.Messaging;
-using SocketService.Framework.Client.Sockets;
-using SocketService.Framework.Data;
+using SocketService.Event;
using SocketService.Net;
using SocketService.Net.Client;
using SocketService.Repository;
diff --git a/SocketService/Command/LogoutUserCommand.cs.orig b/SocketService/Command/LogoutUserCommand.cs.orig
new file mode 100644
index 0000000..49b463b
--- /dev/null
+++ b/SocketService/Command/LogoutUserCommand.cs.orig
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using SocketService.Actions;
+<<<<<<< Updated upstream
+using SocketService.Core.Messaging;
+=======
+using SocketService.Framework.Client.Event;
+using SocketService.Framework.Client.Sockets;
+using SocketService.Framework.Data;
+using SocketService.Framework.Messaging;
+using SocketService.Net;
+>>>>>>> Stashed changes
+using SocketService.Net.Client;
+using SocketService.Repository;
+
+namespace SocketService.Command
+{
+ [Serializable]
+ internal class LogoutUserCommand : BaseMessageHandler
+ {
+ private readonly Guid _clientId;
+
+ public LogoutUserCommand(Guid clientId)
+ {
+ _clientId = clientId;
+ }
+
+ public override void Execute()
+ {
+ Logger.InfoFormat("Client {0} logging out.", _clientId);
+
+ var connection = ConnectionRepository.Instance.Query( c => c.ClientId == _clientId).FirstOrDefault();
+ if (connection != null)
+ ConnectionRepository.Instance.RemoveConnection(connection);
+
+ var clientSocket = SocketRepository.Instance.FindByClientId(_clientId);
+ if (clientSocket != null)
+ {
+ try
+ {
+ clientSocket.Close();
+ }
+ catch (Exception ex)
+ {
+ Logger.Error(ex.ToString());
+ }
+ }
+
+ var user = UserRepository.Instance.Query(u => u.ClientKey == _clientId).FirstOrDefault();
+ if (user != null && user.Room != null)
+ {
+ var userList = user.Room.Users.Select(u => u.ClientKey);
+ MSMQQueueWrapper.QueueCommand(
+ new BroadcastObjectCommand(userList.ToArray(),
+ new PublicMessageEvent
+ {
+ RoomId = (int) user.RoomId,
+ UserName = string.Empty,
+ Message = string.Format("{0} has logged out.", user.Name),
+ ZoneId = (int) user.Room.ZoneId
+ })
+ );
+ }
+
+ UserActionEngine.Instance.LogoutUser(_clientId);
+ }
+ }
+}
\ No newline at end of file
diff --git a/SocketService/Command/NegotiateKeysCommand.cs b/SocketService/Command/NegotiateKeysCommand.cs
index 837deff..0b63c69 100644
--- a/SocketService/Command/NegotiateKeysCommand.cs
+++ b/SocketService/Command/NegotiateKeysCommand.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using SocketService.Core.Messaging;
using SocketService.Net.Client;
using SocketService.Shared.Response;
diff --git a/SocketService/Command/NegotiateKeysCommand.cs.orig b/SocketService/Command/NegotiateKeysCommand.cs.orig
new file mode 100644
index 0000000..ce308df
--- /dev/null
+++ b/SocketService/Command/NegotiateKeysCommand.cs.orig
@@ -0,0 +1,61 @@
+using System;
+<<<<<<< Updated upstream
+using SocketService.Core.Messaging;
+=======
+using System.Linq;
+using SocketService.Framework.Client.Response;
+using SocketService.Framework.Messaging;
+>>>>>>> Stashed changes
+using SocketService.Net.Client;
+using SocketService.Shared.Response;
+
+namespace SocketService.Command
+{
+ [Serializable]
+ public class NegotiateKeysCommand : BaseMessageHandler
+ {
+ private readonly Guid _clientId;
+ private readonly byte[] _publicKey;
+
+ public NegotiateKeysCommand(Guid clientId, byte[] publicKey)
+ {
+ _publicKey = publicKey;
+ _clientId = clientId;
+ }
+
+ public override void Execute()
+ {
+ var connection =
+ ConnectionRepository.Instance.Query(c => c.ClientId == _clientId).FirstOrDefault();
+
+ {
+ //connection.RemotePublicKey = connection.Provider.Import(_data);
+
+ //ZipSocket zipSocket = SocketRepository.Instance.FindByClientId(connection.ClientId);
+ //if (zipSocket != null)
+ //{
+ // zipSocket.SendData(connection.Provider.PublicKey.ToByteArray());
+
+ // // we are done here
+ // connection.ConnectionState = ConnectionState.Connected;
+ //}
+
+ //NegotiateKeysRequest negotiateKeysRequest = request as NegotiateKeysRequest;
+ //Guid clientId = (Guid)state;
+
+ //Connection connection = ConnectionRepository.Instance.FindConnectionByClientId(clientId);
+ //if (connection != null)
+ //{
+ // import clients public key
+ connection.RemotePublicKey = connection.SecureKeyProvider.Import(_publicKey);
+
+ // send our public key back
+ var response = new NegotiateKeysResponse {RemotePublicKey = connection.SecureKeyProvider.PublicKey.ToByteArray()};
+
+ // now we send a response back
+ MSMQQueueWrapper.QueueCommand(new SendObjectCommand(_clientId, response));
+ //}
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SocketService/Command/ParseRequestCommand.cs b/SocketService/Command/ParseRequestCommand.cs
index 346258e..a596923 100644
--- a/SocketService/Command/ParseRequestCommand.cs
+++ b/SocketService/Command/ParseRequestCommand.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using SocketService.Client.Core.Request;
using SocketService.Core.Crypto;
using SocketService.Core.Messaging;
diff --git a/SocketService/Command/ParseRequestCommand.cs.orig b/SocketService/Command/ParseRequestCommand.cs.orig
new file mode 100644
index 0000000..6f585c2
--- /dev/null
+++ b/SocketService/Command/ParseRequestCommand.cs.orig
@@ -0,0 +1,86 @@
+using System;
+<<<<<<< Updated upstream
+using SocketService.Client.Core.Request;
+using SocketService.Core.Crypto;
+using SocketService.Core.Messaging;
+=======
+using System.Linq;
+using SocketService.Framework.Client.Request;
+using SocketService.Framework.Messaging;
+using SocketService.Framework.Client.Serialize;
+using SocketService.Crypto;
+>>>>>>> Stashed changes
+using SocketService.Net.Client;
+using SocketService.Repository;
+using SocketService.Shared;
+
+namespace SocketService.Command
+{
+ [Serializable]
+ class ParseRequestCommand : BaseMessageHandler
+ {
+ private readonly byte[] _serialized;
+ private readonly Guid _clientId;
+
+ public ParseRequestCommand(Guid clientId, byte[] serialized)
+ {
+ _serialized = serialized;
+ _clientId = clientId;
+ }
+
+ public override void Execute()
+ {
+ var requestWrapper = ObjectSerialize.Deserialize(_serialized);
+ var payload = DecryptRequest(requestWrapper);
+
+ var handlerType = payload.GetType();
+ var handlerList = ServiceHandlerLookup.Instance.GetHandlerListByType(handlerType);
+
+ MSMQQueueWrapper.QueueCommand(
+ new HandleClientRequestCommand(_clientId, payload, handlerList)
+ );
+ }
+
+ private object DecryptRequest(ClientRequestWrapper requestWrapper)
+ {
+ // switch on encryption type, and create a decryptor for that type
+ // with the remote private key and iv as salt
+ var algorithm = AlgorithmType.AES;
+
+ switch (requestWrapper.Encryption)
+ {
+ case EncryptionType.DES:
+ algorithm = AlgorithmType.DES;
+ break;
+
+ case EncryptionType.TripleDES:
+ algorithm = AlgorithmType.TripleDES;
+ break;
+
+ case EncryptionType.None:
+ algorithm = AlgorithmType.None;
+ break;
+ }
+
+
+ if (algorithm == AlgorithmType.None)
+ {
+ return ObjectSerialize.Deserialize(requestWrapper.RequestData);
+ }
+
+ var connection = ConnectionRepository.Instance.Query( c => c.ClientId == _clientId).FirstOrDefault();
+ if (connection == null)
+ {
+ return null;
+ }
+
+ var privateKey = connection.SecureKeyProvider.CreatePrivateKey(connection.RemotePublicKey);
+ using (var cryptoWrapper = Wrapper.CreateDecryptor(algorithm,
+ privateKey.ToByteArray(),
+ requestWrapper.EncryptionPublicKey))
+ {
+ return ObjectSerialize.Deserialize(cryptoWrapper.Decrypt(requestWrapper.RequestData));
+ }
+ }
+ }
+}
diff --git a/SocketService/SocketService.cs b/SocketService/SocketService.cs
index bffe689..04400ee 100644
--- a/SocketService/SocketService.cs
+++ b/SocketService/SocketService.cs
@@ -24,7 +24,7 @@ public override void StartService()
_messageServer.Start();
}
- private void InitializeCounters()
+ private static void InitializeCounters()
{
try
{
@@ -37,12 +37,12 @@ private void InitializeCounters()
var cdCounter2 =
new CounterCreationData();
- cdCounter1.CounterName = "Total Bytes Received";
- cdCounter1.CounterHelp = "Total number of bytes recieved";
+ cdCounter1.CounterName = "Total Requests Handled";
+ cdCounter1.CounterHelp = "Total number of requests handled";
cdCounter1.CounterType = PerformanceCounterType.NumberOfItems64;
- cdCounter2.CounterName = "Total Bytes Sent";
- cdCounter2.CounterHelp = "Total number of bytes transmitted.";
- cdCounter2.CounterType = PerformanceCounterType.NumberOfItems64;
+ cdCounter2.CounterName = "Requests Per Secpmd";
+ cdCounter2.CounterHelp = "Average number of requests per second.";
+ cdCounter2.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
// Add both counters to the collection.
counterDatas.Add(cdCounter1);
diff --git a/SocketService/SocketService.cs.orig b/SocketService/SocketService.cs.orig
new file mode 100644
index 0000000..e19e82f
--- /dev/null
+++ b/SocketService/SocketService.cs.orig
@@ -0,0 +1,75 @@
+<<<<<<< Updated upstream
+using System.ServiceProcess;
+using SocketService.Core.Messaging;
+=======
+using System;
+using System.Diagnostics;
+using System.ServiceProcess;
+using SocketService.Framework;
+using SocketService.Framework.Messaging;
+>>>>>>> Stashed changes
+using SocketService.Net;
+
+namespace SocketService
+{
+ public partial class SocketService : SocketServiceBase
+ {
+ private readonly SocketManager _serverManager = new SocketManager();
+ private readonly MessageServer _messageServer = new MessageServer();
+
+ public SocketService()
+ {
+ InitializeComponent();
+ }
+
+ public override void StartService()
+ {
+ InitializeCounters();
+
+ _serverManager.StartServer();
+ _messageServer.Start();
+ }
+
+ private void InitializeCounters()
+ {
+ try
+ {
+ var counterDatas =
+ new CounterCreationDataCollection();
+
+ // Create the counters and set their properties.
+ var cdCounter1 =
+ new CounterCreationData();
+ var cdCounter2 =
+ new CounterCreationData();
+
+ cdCounter1.CounterName = "Total Bytes Received";
+ cdCounter1.CounterHelp = "Total number of bytes recieved";
+ cdCounter1.CounterType = PerformanceCounterType.NumberOfItems64;
+ cdCounter2.CounterName = "Total Bytes Sent";
+ cdCounter2.CounterHelp = "Total number of bytes transmitted.";
+ cdCounter2.CounterType = PerformanceCounterType.NumberOfItems64;
+
+ // Add both counters to the collection.
+ counterDatas.Add(cdCounter1);
+ counterDatas.Add(cdCounter2);
+
+ // Create the category and pass the collection to it.
+ PerformanceCounterCategory.Create(
+ "Socket Service Data Stats", "Stats for the socket service.",
+ PerformanceCounterCategoryType.MultiInstance, counterDatas);
+ }
+ catch (Exception ex)
+ {
+ Logger.Error(ex.ToString());
+ }
+
+ }
+
+ public override void StopService()
+ {
+ _serverManager.StopServer();
+ _messageServer.Stop();
+ }
+ }
+}
diff --git a/SocketService/SocketService.csproj b/SocketService/SocketService.csproj
index 3e04564..aba4d99 100644
--- a/SocketService/SocketService.csproj
+++ b/SocketService/SocketService.csproj
@@ -114,6 +114,9 @@
+
+ Component
+
Component
diff --git a/SocketService/SocketServiceBase.cs b/SocketService/SocketServiceBase.cs
new file mode 100644
index 0000000..04919ae
--- /dev/null
+++ b/SocketService/SocketServiceBase.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Reflection;
+using System.ServiceProcess;
+using System.Threading;
+using log4net;
+
+namespace SocketService
+{
+ public class SocketServiceBase : ServiceBase
+ {
+ protected static ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ public SocketServiceBase()
+ {
+ CanStop = true;
+ CanPauseAndContinue = false;
+ AutoLog = true;
+ RunAsService = true;
+ }
+
+ public bool RunAsService { get; set; }
+
+ ///
+ /// Override in subclasses to start your application code. The code will automatically
+ /// be started as either a service or an application depending on the RunAsService property.
+ ///
+ public virtual void StartService()
+ {
+ }
+
+ ///
+ /// APSServiceBase default implementation for OnStart. This will only be called if RunAsService is set to true.
+ /// Implementers should not override this method. Instead, they should put all service start code in StartService.
+ /// The APSServiceBase will handle starting and stopping appropriately depending on whether RunAsService is set or not.
+ ///
+ ///
+ protected override void OnStart(string[] args)
+ {
+ var thread = new Thread(StartService) {Name = "ServiceThread", IsBackground = false};
+ thread.Start();
+ }
+
+ ///
+ /// Override in subclasses to stop your application code. This will only be called if RunAsService is true.
+ ///
+ public virtual void StopService()
+ {
+ }
+
+ ///
+ /// APSServiceBase default implementation for OnStop. This will only be called if RunAsService is set to true.
+ /// Implementers should not override this method. Instead, they should put all service shutdown code in StopService.
+ /// The APSServiceBase will handle starting and stopping appropriately depending on whether RunAsService is set or not.
+ ///
+ protected override void OnStop()
+ {
+ StopService();
+ }
+
+ public void Run()
+ {
+ // Set working directory to application directory.
+ // Otherwise Windows/System32 is used.
+ Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
+
+ // We must start the server appropriately depending on whether we are a service or not.
+ if (RunAsService)
+ {
+ Run(this);
+ }
+ else
+ {
+ StartService();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SocketService/app.config b/SocketService/app.config
index b158ceb..5c00b49 100644
--- a/SocketService/app.config
+++ b/SocketService/app.config
@@ -65,17 +65,11 @@
-
-
-
-
-
-
+
-
diff --git a/SocketService/app.config.orig b/SocketService/app.config.orig
new file mode 100644
index 0000000..e712c80
--- /dev/null
+++ b/SocketService/app.config.orig
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<<<<<<< Updated upstream
+
+
+
+
+=======
+
+
+
+
+
+
+>>>>>>> Stashed changes
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file