diff --git a/zsirozas/Common.cs b/zsirozas/Common.cs index b317a29d1a28555d2b47857fe6bb12458e29294f..67a14c15f12ad082ac5064488ca6ce940dc781ef 100644 --- a/zsirozas/Common.cs +++ b/zsirozas/Common.cs @@ -4,9 +4,10 @@ using System.Net; namespace zsirozas { - //egy generikus szerver API interfész. Emögött lehet a - //-- tényleges szerver (állapot-módosító műveletek, játékos-üzenetek küldése) - //-- "távoli szerver" [TCP-s üzenetekre]/[SignalR hívásokra] fordítás, ellenirányú üzenet-fogadás és továbbítás + /// <summary> + /// A generic interface that provides the game server API. + /// Both actual game servers and remote servers inplement it. + /// </summary> interface IServerApiProvider { void RegisterWrapper(ServerWrapper _wrapper); @@ -24,44 +25,54 @@ namespace zsirozas RoomInfo RoomInfo(string roomID); UserInfo UserInfo(string userID); - //todo uncomment - //szobák: létrehoz, belép, kilép, listáz (név, tagok, vezér, ), játékindít - //játékosok: meghív, listáz void ParseNextMessage(Stream s, object param); object GameAction(string gameID, string userID, PlayerAction action, int cardID); } - //ahogy a szerver látja (és kezeli) a klienst - //ez NEM a kliens kifelé (UI felé) fordított inerfésze - //a SignalR nem tud visszatérési értéket, szerencsére itt nem is használok + /// <summary> + /// The way the server sees the app client. + /// Impleneted by actual game clients and remote clients. + /// </summary> interface IAppClient { + /// <summary> + /// Sends a message about the general context. + /// Such as room status, connection status, etc. + /// </summary> + /// <param name="event">Event.</param> + /// <param name="param0">Param0.</param> void SimpleNotify(ServerEvent @event, string param0); + /// <summary> /// Send a message specific to the game context. /// </summary> /// <param name="event">The GameEvent you want to broadcast.</param> /// <param name="param0">The parameter of the call. It MUST be a JSON string</param> void InGameNotify(GameEvent @event, string param0); + /// <summary> - /// Deprecated! Only use while transitioning from old! + /// Parses the next message from a stream. + /// Only clients that support stream-based protocols need to implement it. /// </summary> - /// <param name="s">a message that will be written to the network stream</param> - void SendMessage(string s); + /// <param name="sr">Sr.</param> void ParseNextMessage(StreamReader sr); + + /// <summary> + /// Validates the clent's connection as an anti-cheat measure. + /// Only remote clients need to implement. (return true if you don't need it) + /// </summary> + /// <param name="connInfo">socket address, connection id, auth token, etc.</param> bool ValidateConnection(object connInfo); } - //2 féle csatlakozási módot kínálok enum ConnectionType { RawTCP, SignalR } - //kapcsolat-felépítős rész partial class User { - //a szervert ne érdekelje, hogy milyen kapcsolatot használunk + //the game server itself doesn't care for the transport protocol public void ConnectClient(ConnectionType type, object backTalk) { ConnectionType = type; diff --git a/zsirozas/GameClient.cs b/zsirozas/GameClient.cs index 5d6a9386772fca07e8b9476318482ffcdaeee177..b0ff7fa4e9e27c96d493d3c6f99b68887883e480 100644 --- a/zsirozas/GameClient.cs +++ b/zsirozas/GameClient.cs @@ -326,10 +326,6 @@ namespace zsirozas } } - public void SendMessage(string s) - { - throw new NotImplementedException(); - } public bool ValidateConnection(object connInfo) { diff --git a/zsirozas/RawTcpTransport.cs b/zsirozas/RawTcpTransport.cs index 3ab68b2a748d2f5842b29de8de9b9647ad55f35e..5adf0fb7ef1dc3a0a8e9e8898f983f6e0c84d451 100644 --- a/zsirozas/RawTcpTransport.cs +++ b/zsirozas/RawTcpTransport.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Net.Sockets; using System.IO; -using System.Threading.Tasks; using System.Net; using System.Web.Script.Serialization; using System.Linq; @@ -29,15 +28,6 @@ namespace zsirozas // Implementation of the server API // - public void SendMessage(string message) - { - lock (messageStreamW) - { - messageStreamW.WriteLine(message); - messageStreamW.Flush(); - } - } - public void InGameNotify(GameEvent @event, string param0) { lock (messageStreamW) @@ -244,7 +234,7 @@ namespace zsirozas string status = null; sw.WriteLine(ServerAction.StartGame); - //sw.WriteLine(userID); //TODO: hoppá! erre nem gondoltam + //sw.WriteLine(userID); //TODO: hoppá! ez még hiányzik sw.WriteLine(roomID); sw.Flush(); if ((status = sr.ReadLine()) != "OK") @@ -313,7 +303,7 @@ namespace zsirozas if (action == PlayerAction.GetCards) { - status = sr.ReadLine(); //todo bug néha ez null, utána kivenni a debug cuccokat + status = sr.ReadLine(); //todo bug: néha ez null, utána kivenni a debug cuccokat try { return new JavaScriptSerializer().Deserialize<IEnumerable<Card>>(status).ToArray(); diff --git a/zsirozas/Rooms.cs b/zsirozas/Rooms.cs index cca92ef7ae25c4af69d3f82eec6e21c215902370..93fe69188b6c66a2557c962c4d9faba5a6824db7 100644 --- a/zsirozas/Rooms.cs +++ b/zsirozas/Rooms.cs @@ -96,7 +96,6 @@ namespace zsirozas } } - //TODO: maradjon struct vagy legyen class? class Room { public string gameID = null; diff --git a/zsirozas/ServerWrapper.cs b/zsirozas/ServerWrapper.cs index 5aa69028eca4720bdab98ef300b879e25291dc3e..187dd52b0b022b62e7e2b8219c97f7bc76ee8125 100644 --- a/zsirozas/ServerWrapper.cs +++ b/zsirozas/ServerWrapper.cs @@ -30,7 +30,7 @@ namespace zsirozas { if (enableSignalR) { - //startSignalR(); + startSignalR(); } if (enableTCP) { @@ -101,7 +101,6 @@ namespace zsirozas } public void startSignalR() { - webapp = WebApp.Start(signalr_server_url, Configuration); GlobalHost.DependencyResolver.Register(typeof(SignalRServerHub), () => new SignalRServerHub(serverInstance)); } diff --git a/zsirozas/SignalR-Transport.cs b/zsirozas/SignalR-Transport.cs index 33cd53e147fb3b048882ef8297bc70b77a5dd33b..7fc04cef1529805a403f423abcf130f05a50f843 100644 --- a/zsirozas/SignalR-Transport.cs +++ b/zsirozas/SignalR-Transport.cs @@ -2,7 +2,6 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.SignalR; -//és a klienshez using Microsoft.AspNet.SignalR.Client; using Microsoft.AspNet.SignalR.Client.Transports; @@ -10,7 +9,7 @@ using WrappedException = Microsoft.AspNet.SignalR.HubException; namespace zsirozas { - //............................................................ + //....................client-side........................................ class SignalRRemoteServer : IServerApiProvider { IAppClient client; @@ -191,7 +190,7 @@ namespace zsirozas } - //................................................................................ + //.....................server-side........................................................... class SignalRServerHub : Hub<IAppClient>, IServerApiProvider { @@ -203,6 +202,7 @@ namespace zsirozas appServer = serverInstance; } + //only actual gameservers reference a wrappers public void RegisterWrapper(ServerWrapper _wrapper) { throw new WrappedException("Why would you try to do something like this?"); @@ -384,7 +384,6 @@ namespace zsirozas throw WrapException(ex); } } - } class AppClientWithSignalR : IAppClient { @@ -401,16 +400,9 @@ namespace zsirozas (context as IAppClient).InGameNotify(@event, param0); } - public void ParseNextMessage(StreamReader sr) { - //todo implemtálni valahogy?? - throw new NotImplementedException(); - } - - public void SendMessage(string s) - { - throw new NotImplementedException(); + throw new NotSupportedException("This is a proxy to the real app client. You shouldn't want to feed it message streams."); } public void SimpleNotify(ServerEvent @event, string param0) @@ -424,5 +416,4 @@ namespace zsirozas return this.signalRConnID == (connInfo as string); } } - } \ No newline at end of file