public void TestDiscardCard() { RPCHandler handler = new RPCHandler(); SecretHitlerGame game = new SecretHitlerGame(handler); var connections = new uint[] { 0, 1, 2 }; var names = new string[] { "0", "1", "2" }; game.Init(); game.OnStart(connections, names); game.OnTick(); Assert.AreEqual(game.President, 0); Assert.AreEqual(game.Cancellor, -1); TestHelper.WrapAction(0, game.SelectCancellor, 1); Assert.AreEqual(game.President, 0); Assert.AreEqual(game.Cancellor, 1); TestHelper.WrapAction(0, game.Vote, true); TestHelper.WrapAction(1, game.Vote, true); Assert.AreEqual(game.President, 0); Assert.AreEqual(game.Cancellor, 1); }
public static RPCEntry Pop(RPCHandler handler, params object[] args) { RPCEntry rpcEntry = POOL.Pop(); rpcEntry.handler = handler; rpcEntry.args = args; return(rpcEntry); }
public void Send(ushort tokenId, Packet packet, RPCHandler callback) { KCPUserToken token = this._tokenManager.Get(tokenId); this._rpcManager.Accept(token, packet, callback); packet.OnSend(); token?.Send(packet); }
// Use this for initialization void Start() { RPCHandler handler = new RPCHandler(); RPCParser parser = new RPCParser(handler); _client = new ClientNetworking(parser, "localhost", 7777); _client.connect(); handler.addResponseListener("numberResult", handleResult, handleError); }
public void Accept(Packet packet, RPCHandler callback) { if (!packet.isRPCCall) { return; } ushort pid = this.GetNextPacketId(); packet.pid = pid; this._rpcHandlers[pid] = callback; }
public void Invoke(Packet packet) { if (!packet.isRPCReturn) { return; } RPCHandler handler = this._rpcHandlers[packet.srcPid]; this._rpcHandlers.Remove(packet.srcPid); handler.Invoke(null, packet); }
public void Invoke(IUserToken token, Packet packet) { if (!packet.isRPCReturn) { return; } Dictionary <ushort, RPCHandler> map = this._rpcsHandlers[token]; RPCHandler handler = map[packet.srcPid]; map.Remove(packet.srcPid); handler.Invoke(token, packet); }
public SecretHitlerGame GetStartState() { RPCHandler handler = new RPCHandler(); SecretHitlerGame game = new SecretHitlerGame(handler); game.Init(); game.OnStart(connections, names); game.OnTick(); return(game); }
public void Accept(IUserToken token, Packet packet, RPCHandler callback) { if (!packet.isRPCCall) { return; } ushort pid = this.GetNextPacketId(token); packet.pid = pid; Dictionary <ushort, RPCHandler> handlers = this._rpcsHandlers[token]; handlers[pid] = callback; }
IEnumerator coLogin(LoginRequest request, RPCHandler <LoginReply> handler) { try { var reply = client.Login(request); handler(reply); } catch (Grpc.Core.RpcException e) { Debug.LogError("RPC failed " + e); } yield return(null); }
IEnumerator coRpcServiceExample(RpcServiceExampleRequest request, RPCHandler <RpcServiceExampleReply> handler) { try { var reply = client.RpcServiceExample(request); handler(reply); } catch (Grpc.Core.RpcException e) { Debug.LogError("RPC failed " + e); } yield return(null); }
IEnumerator coLogin(LoginRequest request, RPCHandler <LoginReply> handler) { //try //{ // var reply = client.Login(request); // handler(reply); //} //catch (Grpc.Core.RpcException e) //{ // Debug.LogError("RPC failed " + e); //} yield return(null); }
// Use this for initialization void Start() { Application.runInBackground = true; // RPC RPCHandler handler = new RPCHandler(); IRPCParser rpcParser = new RPCParser(handler); // Server ServerNetworking server = new ServerNetworking(rpcParser, 7777); server.CreateServer(); Calculator calc = new Calculator(handler); }
IEnumerator coRankingList(RankingListRequest request, RPCHandler <RankingListReply> handler) { //try //{ // var metaData = new Metadata // { // { "access_key", GameDataManager.Instance.userData.accessKey } // }; // var reply = client.RankingList(request, metaData); // handler(reply); //} //catch (Grpc.Core.RpcException e) //{ // Debug.LogError("RPC failed " + e); //} yield return(null); }
public MatchLobbyContext MakeLobbyContext() { if (IsHost) { var lobby = new MatchLobby(GameData.Scenarios.First()); lobby.ApplyAction(new AddPlayerAction(Player)); var chat = new Chat(); Server.MessageAdapter = new NonMatchMessageSerializer(); Server.RPCHandler = new RPCHandler().Install( new LobbyServerLayer(lobby, ConnectionCache), new ChatServerLayer(chat, ConnectionCache)); lobby.OnActionApplied += (sender, e) => Server.Broadcast(new ApplyLobbyActionRequest(e.Value)); chat.OnActionApplied += (sender, e) => Server.Broadcast(new ApplyChatActionRequest(e.Value)); return(new MatchLobbyContext(Server, ConnectionCache, lobby, chat)); } else { var chat = new Chat(); Client.MessageAdapter = new NonMatchMessageSerializer(); var lobbyLayer = new LobbyLayer(); var handler = new RPCHandler().Install(lobbyLayer, new ChatLayer(chat)); Client.RPCHandler = handler; if (Client.Call( new ApplyLobbyActionRequest(new AddPlayerAction(Player))).Get <BooleanResponse>().Value) { MatchLobby lobby = Client.Call(new GetLobbyRequest()).Get <GetLobbyResponse>().Lobby; lobbyLayer.Lobby = lobby; return(new MatchLobbyContext(Client, lobby, chat)); } return(null); } }
public void handleMessage(byte[] msg) { BinaryReader reader = new BinaryReader(new MemoryStream(msg)); int cmd = reader.ReadInt16(); if (cmd == 0) { bool ok = reader.ReadBoolean(); if (ok) { ConnectionId = reader.ReadUInt32(); this.Username = reader.ReadString(); SceneManager.LoadScene("LobbyScene", LoadSceneMode.Single); } else { this.State = 0; this.Error = true; this.ErrorMessage = reader.ReadString(); } } else if (cmd == 2) { var connId = reader.ReadUInt32(); if (connId == ConnectionId) { this.State = 2; GameLobby = new GameLobby(); GameLobby.Players.Add(connId, new GameLobbyPlayer(connId, reader.ReadString())); SceneManager.LoadScene("GameLobbyScene", LoadSceneMode.Single); } else { GameLobby.Players.Add(connId, new GameLobbyPlayer(connId, reader.ReadString())); } } else if (cmd == 3) { var connId = reader.ReadUInt32(); GameLobby.HostId = connId; } else if (cmd == 4) { var connId = reader.ReadUInt32(); if (connId == ConnectionId) { State = 1; GameLobby = null; } else { GameLobby.Players.Remove(connId); } } else if (cmd == 5) { var gameId = reader.ReadUInt32(); RPCHandler RPCHandler = new RPCHandler(); game = new SecretHitlerGame(RPCHandler); FindObjectOfType <GameData>().setGameData(game); game.Init(); uint[] ids = new uint[this.GameLobby.Players.Count]; string[] names = new string[this.GameLobby.Players.Count]; int index = 0; foreach (var p in this.GameLobby.Players.Values) { ids[index] = p.ConnectionId; names[index] = p.Username; index++; } game.OnStart(ids, names); SceneManager.LoadScene("SecretHitler", LoadSceneMode.Single); } else if (cmd == 6) { //RPC } else if (cmd == 7) { //tick game.OnTick(); Debug.Log("Tick"); } }
public void Send(ushort tokenId, Packet packet, RPCHandler callback) { }
// RankingList public void RankingList(RankingListRequest request, RPCHandler <RankingListReply> handler) { StartCoroutine(coRankingList(request, handler)); }
public void Clear() { this.handler = null; this.args = null; }
// LoadGameData public void LoadGameData(LoadGameDataRequest request, RPCHandler <LoadGameDataReply> handler) { StartCoroutine(coLoadGameData(request, handler)); }
// SaveGameData public void SaveGameData(SaveGameDataRequest request, RPCHandler <SaveGameDataReply> handler) { StartCoroutine(coSaveGameData(request, handler)); }
// Login public void Login(LoginRequest request, RPCHandler <LoginReply> handler) { StartCoroutine(coLogin(request, handler)); }
public void Install(RPCHandler Handler) { Handler.RegisterRPC <ExecuteOrderRequest>(ExecuteOrder); Handler.RegisterRPC <ValidateOrderRequest>(ValidateOrder); }
public void Install(RPCHandler Handler) { Handler.RegisterRPC <ApplyLobbyActionRequest>(ApplyLobbyAction); Handler.RegisterRPC <GetLobbyRequest>(GetLobby); }
// HealthCheck - Check //public void Check(HealthCheckRequest request, RPCHandler<HealthCheckResponse> handler) //{ // healthCheckThread = new Thread(() => // { // int intervalTime = 60 * 1000;//Time.time + (10.0f * 60.0f); // //try // //{ // // while (running) // // { // // //if (Time.time < intervalTime) // // //{ // // // continue; // // //} // // var metaData = new Metadata // // { // // { "access_key", GameDataManager.Instance.userData.accessKey } // // }; // // var reply = health.Check(request, metaData); // // handler(reply); // // Thread.Sleep(intervalTime); // // } // //} // //catch (Grpc.Core.RpcException e) // //{ // // Debug.LogError("RPC failed " + e); // //} // }); // healthCheckThread.Start(); // //StartCoroutine(coCheck(request, handler)); //} //IEnumerator coCheck(HealthCheckRequest request, RPCHandler<HealthCheckResponse> handler) //{ // try // { // while (running) // { // //if (Time.time < intervalTime) // //{ // // continue; // //} // var metadata = new Metadata // { // { "access_key", GameDataManager.Instance.userData.accessKey } // }; // var reply = health.Check(request, metadata); // handler(reply); // } // } // catch (Grpc.Core.RpcException e) // { // Debug.LogError("RPC failed " + e); // } // yield return null; //} // HealthCheck - Watch //public void Watch(HealthCheckRequest request, // RPCHandler<HealthCheckResponse> handler) //{ // //coWatch(request, handler); // //await task; // //StartCoroutine(coWatch(request, handler)); // //await coWatch(request, handler); // healthWatchThread = new Thread(async () => // { // //try // //{ // // while (running) // // { // // var metaData = new Metadata // // { // // { "access_key", GameDataManager.Instance.userData.accessKey } // // }; // // using (var call = health.Watch(request, metaData)) // // { // // while (await call.ResponseStream.MoveNext()) // // { // // HealthCheckResponse reply = call.ResponseStream.Current; // // handler(reply); // // } // // } // // } // //} // //catch (Grpc.Core.RpcException e) // //{ // // Debug.LogError("RPC failed " + e); // //} // }); // healthWatchThread.Start(); //} //void coWatch(HealthCheckRequest request, // RPCHandler<HealthCheckResponse> handler) //{ // Thread thread = new Thread(async () => // { // try // { // using (var call = health.Watch(request)) // { // while (await call.ResponseStream.MoveNext()) // { // HealthCheckResponse reply = call.ResponseStream.Current; // handler(reply); // } // } // //var reply = health.Watch(request); // //handler(reply); // } // catch (Grpc.Core.RpcException e) // { // Debug.LogError("RPC failed " + e); // } // }); //} // RpcServiceExample public void RpcServiceExample(RpcServiceExampleRequest request, RPCHandler <RpcServiceExampleReply> handler) { StartCoroutine(coRpcServiceExample(request, handler)); }
public static void Send(string serverName, ushort tokenId, Packet packet, RPCHandler callback = null) { GetServer(serverName)?.Send(tokenId, packet, callback); }
public static void Send(string clientName, Packet packet, RPCHandler callback = null) { GetClient(clientName)?.Send(packet, callback); }
public void Install(RPCHandler Handler) { Handler.RegisterRPC <LogInPlayerRequest>(LogInPlayer); Handler.RegisterRPC <RegisterPlayerRequest>(RegisterPlayer); Handler.RegisterRPC <GetUnitConfigurationPacksRequest>(GetUnitConfigurationPacks); }
public void Send(Packet packet, RPCHandler callback = null) { this._rpcManager.Accept(packet, callback); packet.OnSend(); this.Send(NetworkHelper.EncodePacket(packet)); }
public void Install(RPCHandler Handler) { Handler.RegisterRPC <ApplyChatActionRequest>(ApplyChatAction); }