public void HandleEnterReq(long peerId, CodedInputStream stream) { var request = EnterReq.Parser.ParseFrom(stream); Log.Debug(typeof(Program), $"PlayerName: {request.Name}, Token: {request.Token}, DeviceId: {request.DeviceId}"); var isValidToken = IsValidToken(request.Token, request.DeviceId); if (isValidToken.GetAwaiter().GetResult() == false) { var failedRes = new EnterRes() { Result = (int)ResultCode.InvalidToken }; _netServer.Send(peerId, (ushort)PacketCode.EnterRes, failedRes); return; } var enterRes = new EnterRes() { Result = (int)ResultCode.Success, MyPlayer = new PbPlayer() { Id = peerId, Name = request.Name, Pos = GetRandomPos(), Vel = new PbPosition() { X = 0.0f, Y = 0.0f } } }; _netServer.Send(peerId, (ushort)PacketCode.EnterRes, enterRes); { var enterEvt = new EnterEvt() { Players = {} }; foreach (var p in _players) { var player = new PbPlayer() { Id = p.Key, Name = p.Value.Name, Pos = p.Value.Src }; enterEvt.Players.Add(player); } _netServer.Send(peerId, (ushort)PacketCode.EnterEvt, enterEvt); } { var enterEvt = new EnterEvt() { Players = { enterRes.MyPlayer } }; _netServer.Broadcast((ushort)PacketCode.EnterEvt, enterEvt); } _players[peerId] = new Player() { Id = peerId, Name = request.Name, Src = enterRes.MyPlayer.Pos }; }