Skip to content
Snippets Groups Projects
Commit 76a6cd4d authored by Sillinger Péter's avatar Sillinger Péter
Browse files

Included SignalRTrasport.cs.

parent d0154eda
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ namespace zsirozas ...@@ -17,7 +17,7 @@ namespace zsirozas
string CreateUser(string nickname, ConnectionType type, object backTalk); string CreateUser(string nickname, ConnectionType type, object backTalk);
void RemoveUser(string userID); void RemoveUser(string userID);
string NewGame(string roomID); string NewGame(string roomID);//TODO: hozzáadni hogy (string userID,...)
string[] ListRooms(); string[] ListRooms();
string[] ListUsers(); string[] ListUsers();
ServerInfo ServerInfo(); ServerInfo ServerInfo();
......
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
//és a klienshez
using Microsoft.AspNet.SignalR.Client;
using Microsoft.AspNet.SignalR.Client.Transports;
namespace zsirozas
{
//............................................................
class SignalRRemoteServer : IServerApiProvider
{
IHubProxy hub;
public string CreateUser(string name, ConnectionType type, object backTalk)
{
return hub.Invoke<string>(nameof(CreateUser), name, type, backTalk).Result;
}
public string CreateRoom(string userID)
{
return hub.Invoke<string>(nameof(CreateRoom), userID).Result;
}
public void LeaveRoom(string userID)
{
hub.Invoke(nameof(LeaveRoom), userID).Wait();
}
public void JoinRoom(string userID, string roomID)
{
hub.Invoke(nameof(JoinRoom), roomID).Wait();
}
public void RemoveUser(string userID)
{
hub.Invoke(nameof(RemoveUser), userID).Wait();
}
public string NewGame(string roomID)
{
return hub.Invoke<string>(nameof(NewGame), roomID).Result;
}
IAppClient client;
public SignalRRemoteServer(string server_url)
{
hub = new HubConnection(server_url).CreateHubProxy(nameof(SignalRServerHub));
hub.On<ServerEvent, object>(nameof(client.SimpleNotify), client.SimpleNotify);
hub.On<GameEvent, object>(nameof(client.InGameNotify), client.InGameNotify);
}
}
//................................................................................
class SignalRServerHub : Hub<IAppClient>, IServerApiProvider
{
//a hubok tranziesnek, úgyhogy ezt csak így tudom értelmesen
//TODO: van-e ennek "szebb" módja?
public static IServerApiProvider appServer = new ActualServer();
public SignalRServerHub(IServerApiProvider serverInstance)
{
appServer = serverInstance;
}
public string CreateUser(string name, ConnectionType type, object backTalk)
{
switch (type)
{
case ConnectionType.SignalR:
if (backTalk != null) goto default;
backTalk = Context.ConnectionId;
break;
case ConnectionType.RawTCP:
throw new Exception("What? Why?");
default:
throw new NotSupportedException("You can't do that");
}
return appServer.CreateUser(name, type, backTalk);
}
public string CreateRoom(string userID)
{
return appServer.CreateRoom(userID);
}
public void LeaveRoom(string userID)
{
appServer.LeaveRoom(userID);
}
public void JoinRoom(string userID, string roomID)
{
appServer.JoinRoom(userID, roomID);
}
public void RemoveUser(string userID)
{
appServer.RemoveUser(userID);
}
public string NewGame(string roomID)
{
return appServer.NewGame(roomID);
}
}
class AppClientWithSignalR : IAppClient
{
public string signalRConnID;
public AppClientWithSignalR(string backTalk)
{
this.signalRConnID = backTalk;
}
public void InGameNotify(GameEvent @event, object param0)
{
var context = GlobalHost.ConnectionManager.GetHubContext<SignalRServerHub>();
(context as IAppClient).InGameNotify(@event, param0);
}
public void SimpleNotify(ServerEvent @event, object param0)
{
var context = GlobalHost.ConnectionManager.GetHubContext<SignalRServerHub>();
(context as IAppClient).SimpleNotify(@event, param0);
}
}
}
\ No newline at end of file
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
<Compile Include="Common.cs" /> <Compile Include="Common.cs" />
<Compile Include="RawTcpTransport.cs" /> <Compile Include="RawTcpTransport.cs" />
<Compile Include="Rooms.cs" /> <Compile Include="Rooms.cs" />
<Compile Include="SignalR-Transport.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment