Ejemplo n.º 1
0
        public LobbyResponse Lobby(ClientSession session, LobbyRequest request)
        {
            session.PublicKey = request.PublicKey;
            var response = new LobbyResponse();

            response.Token = request.Token;
            try
            {
                if (session.HasLobby)
                {
                    var chatLobby = ChatLobbyManager.GetLobby(session.ChatLobbyId);
                    response.Latitude         = chatLobby.Latitude;
                    response.Longitude        = chatLobby.Longitude;
                    response.LobbyId          = chatLobby.LobbyId;
                    response.MemberPublicKeys = chatLobby.GetMemberKeys();
                    response.Range            = chatLobby.Range;
                    response.Success          = true;
                    return(response);
                }
                if (ChatLobbyManager.IsLobbyAvailable())
                {
                    var chatLobbyId = ChatLobbyManager.GetIdForNextOpenLobby();
                    var chatLobby   = ChatLobbyManager.GetLobby(chatLobbyId);
                    chatLobby.JoinLobby(session);
                    response.Latitude         = chatLobby.Latitude;
                    response.Longitude        = chatLobby.Longitude;
                    response.LobbyId          = chatLobby.LobbyId;
                    response.MemberPublicKeys = chatLobby.GetMemberKeys();
                    response.Range            = chatLobby.Range;
                    response.Success          = true;
                    return(response);
                }
                else
                {
                    var chatLobbyId = ChatLobbyManager.CreateLobby(session, request.Longitude, request.Latitude);
                    var chatLobby   = ChatLobbyManager.GetLobby(chatLobbyId);
                    response.Latitude         = chatLobby.Latitude;
                    response.Longitude        = chatLobby.Longitude;
                    response.LobbyId          = chatLobby.LobbyId;
                    response.MemberPublicKeys = chatLobby.GetMemberKeys();
                    response.Range            = chatLobby.Range;
                    response.Success          = true;
                    return(response);
                }
            }
            catch (Exception exc)
            {
                log.Error("Error on LobbyRequest", exc);
                response.Success = false;
                return(response);
            }
        }
Ejemplo n.º 2
0
        public static LobbiesResponse getLobbiesResponse()
        {
            //lobbies.Add(new Lobby(1, "SCHWERERPANZERSPÄHWAGENSIEBENKOMMAFÜNFZENTIMETERSONDERKRAFTFAHRZEUGZWEIHUNDERTVIERUNDDREISSIGVIERPANZERABWEHRKANONENWAGEN"));
            List <LobbyResponse> responses = new List <LobbyResponse>();

            for (int i = 0; i < lobbies.Count; i++)
            {
                Lobby         l  = lobbies[i];
                LobbyResponse lr = new LobbyResponse(l.Id, l.Name, l.PlayersNumber, l.Status.ToString());
                responses.Add(lr);
            }
            LobbiesResponse response = new LobbiesResponse(responses);

            return(response);
        }
Ejemplo n.º 3
0
        public void UpdateLobby(object sender = null, ElapsedEventArgs args = null)
        {
            LobbyResponse message = new LobbyResponse
            {
                Players = _players,
                Started = false
            };

            if (_started)
            {
                SendStartedResponse();
            }
            else
            {
                _sender.SendResponse(message, _players.Select(x => x.Connection).ToList());
            }
        }
Ejemplo n.º 4
0
        public void Update(LobbyResponse message)
        {
            if (isExiting)
            {
                return;
            }
            int index = 0;

            List <LobbyPlayer> players = message.Players;

            slots.ForEach((slot) =>
            {
                if (index >= message.Players.Count)
                {
                    Invoke(new Action(() =>
                    {
                        slot.UsernameLabel.Text = "-";
                        slot.ReadyLabel.Visible = false;
                    }));
                }
                else
                {
                    LobbyPlayer player = players[index];
                    Invoke(new Action(() =>
                    {
                        slot.UsernameLabel.Text = player.Name;
                        slot.ReadyLabel.Visible = player.Ready;
                    }));
                }

                index++;
            });

            Invoke(new Action(() =>
            {
                ReadyButton.Text = players.Find(x => x.Name == _storage.CurrentPlayer.Name).Ready ? "UNREADY" : "READY";
                Go.Visible       = players.TrueForAll(x => x.Ready);
            }));

            _udpSender.Send(new KeepAliveRequest
            {
                Name = _storage.CurrentPlayer.Name
            });
        }
Ejemplo n.º 5
0
        // Start is called before the first frame update
        void Start()
        {
            Debug.Log("Starting server on port " + port + "...");

            Debug.Log("Registering with lobbymanager... (" + lobbyManager + ")");
            UnityWebRequest wr = UnityWebRequest.Post(lobbyManager + "/api/lobby/new/" + port, "");

            wr.SendWebRequest();
            while (!wr.isDone)
            {
                ;
            }
            try
            {
                this.lobby = JsonUtility.FromJson <LobbyResponse>(wr.downloadHandler.text);
            }
            catch (ArgumentException e)
            {
                Debug.LogError(wr.downloadHandler.text);
                Debug.LogError(e);
            }
            Debug.Log("Sever has ID " + this.lobby.id);
            // Start lobbymanager heartbeat
            InvokeRepeating("Heartbeat", 1f, 10f);


            Debug.Log("Loading game...");
            //Runs the GameLoader script
            (Resources.Load("GameLoader") as GameObject).GetComponent <GameLoader>().Init();
            this.TaskQueue  = new ConcurrentQueue <Action>();
            Server.instance = this;


            Debug.Log("Listening for new connections...");
            UDPServer.getInstance().Init(this, port);
            Debug.Log("Loading complete");
        }
        public ActionResult RefreshLobbiesList(string gameName)
        {
            var lobbies = _lobbyService.FindAllByGameName(gameName);

            return(Json(LobbyResponse.Create(lobbies)));
        }
Ejemplo n.º 7
0
        private Task Update(SocketBase socket)
        {
            LobbyResponse lobbyResponse = socket as LobbyResponse ?? throw new ArgumentNullException(nameof(socket));

            return(_lobbyManager.Update(lobbyResponse));
        }
Ejemplo n.º 8
0
 public Task Update(LobbyResponse lobbyResponse)
 {
     _lobbyForm?.Update(lobbyResponse);
     return(Task.CompletedTask);
 }