Skip to content

Commit

Permalink
blah blah
Browse files Browse the repository at this point in the history
  • Loading branch information
soshimozi committed Nov 1, 2011
1 parent 37cd1c3 commit 7a81d11
Show file tree
Hide file tree
Showing 127 changed files with 14,055 additions and 0 deletions.
Binary file added Database/ServerData.sdf.fucked
Binary file not shown.
177 changes: 177 additions & 0 deletions SocketService.Client.Core/ClientEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using System;
using System.Collections.Generic;
using SocketService.Client.Core.Manager;
using SocketService.Event;
using SocketService.Shared.Response;

namespace SocketService.Client.Core
{
public class ClientEngine
{
public event EventHandler<ServerMessageReceivedArgs> ServerMessageRecieved;
public event EventHandler<LoginResponseEventArgs> LoginResponseReceived;
public event EventHandler<GetRoomVariableResponseArgs> GetRoomVariableResponseRecieved;
public event EventHandler<JoinRoomEventArgs> JoinRoom;
public event EventHandler<RoomUserUpdateEventArgs> RoomUserUpdate;
public event EventHandler<LeaveRoomEventArgs> LeaveRoom;
public event EventHandler<RoomVariableUpdateArgs> RoomVariableUpdate;

private readonly List<Server> _servers = new List<Server>();

public ClientEngine()
{
Managers = new ManagerHelper(this);
}

public ManagerHelper Managers { get; private set; }

public void AddServer(Server server)
{
lock (_servers)
{
_servers.Add(server);
}

server.ServerEvent += ServerServerEvent;
server.ServerResponse += ServerServerResponse;
}

public void StopEngine()
{
lock (_servers)
{
foreach (var server in _servers)
{
server.Disconnect();
}
}
}

protected void ServerServerResponse(object sender, ServerResponseEventArgs e)
{
HandleServerResponse(e.Response);
}

protected void ServerServerEvent(object sender, ServerEventEventArgs e)
{
HandleEvent(e.ServerEvent);
}

private void HandleServerResponse(IServerResponse response)
{
if (response is GetRoomVariableResponse)
{
OnGetRoomVariableResponseRecieved(
new GetRoomVariableResponseArgs
{
Response = response as GetRoomVariableResponse
}
);
}
else if (response is LoginResponse)
{
OnLoginResponseReceieved(
new LoginResponseEventArgs
{
Response = response as LoginResponse
}
);
}
}

private void HandleEvent(IEvent evt)
{
if (evt is JoinRoomEvent)
{
OnJoinRoomEvent(
new JoinRoomEventArgs
{
Event = evt as JoinRoomEvent
}
);
}
else if (evt is RoomUserUpdateEvent)
{
OnRoomUserUpdate(
new RoomUserUpdateEventArgs
{
Event = evt as RoomUserUpdateEvent
}
);
}
else if (evt is RoomVariableUpdateEvent)
{
OnRoomVariableUpdate(
new RoomVariableUpdateArgs
{
Event = evt as RoomVariableUpdateEvent
}
);
}
}

protected virtual void OnRoomVariableUpdate(RoomVariableUpdateArgs args)
{
var func = RoomVariableUpdate;
if (func != null)
{
func(this, args);
}
}

protected virtual void OnLeaveRoom(LeaveRoomEventArgs args)
{
var func = LeaveRoom;
if (func != null)
{
func(this, args);
}
}


protected virtual void OnRoomUserUpdate(RoomUserUpdateEventArgs args)
{
var func = RoomUserUpdate;
if (func != null)
{
func(this, args);
}
}

protected virtual void OnGetRoomVariableResponseRecieved(GetRoomVariableResponseArgs args)
{
var func = GetRoomVariableResponseRecieved;
if (func != null)
{
func(this, args);
}
}

protected virtual void OnServerMessageReceived(ServerMessageReceivedArgs args)
{
var func = ServerMessageRecieved;
if (func != null)
{
func(this, args);
}
}

protected virtual void OnLoginResponseReceieved(LoginResponseEventArgs args)
{
var func = LoginResponseReceived;
if (func != null)
{
func(this, args);
}
}

protected virtual void OnJoinRoomEvent(JoinRoomEventArgs args)
{
var func = JoinRoom;
if (func != null)
{
func(this, args);
}
}
}
}
6 changes: 6 additions & 0 deletions SocketService.Client.Core/Composition/IPluginMetaData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SocketService.Framework.Client.Composition
{
public interface IPluginMetaData
{
}
}
11 changes: 11 additions & 0 deletions SocketService.Client.Core/Composition/PluginMetaDataAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.ComponentModel.Composition;

namespace SocketService.Framework.Client.Composition
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
public class PluginMetaDataAttribute : ExportAttribute, IPluginMetaData
{
}
}
Loading

0 comments on commit 7a81d11

Please sign in to comment.