Esempio n. 1
0
        public (bool, string) GetMatchInfoString(string matchKey)
        {
            var sendMsg  = new GetMatchInfoMessage(matchKey);
            var sendJson = JsonConvert.SerializeObject(sendMsg);

            var(r, recvJson) = SocketManager.SendRecv(sendJson);
            return((r)
                                ? (true, recvJson)
                                : (false, ""));
        }
Esempio n. 2
0
        /// <summary>
        /// 試合情報の取得
        /// </summary>
        /// <param name="matchKey">部屋名</param>
        /// <returns>試合情報</returns>
        public (bool, MatchInfo) GetMatchInfo(string matchKey)
        {
            var sendMsg  = new GetMatchInfoMessage(matchKey);
            var sendJson = JsonConvert.SerializeObject(sendMsg);

            var(r, recvJson) = SocketManager.SendRecv(sendJson);
            return((r)
                                ? (true, JsonConvert.DeserializeObject <MatchInfo>(recvJson))
                                : (false, new MatchInfo()));
        }
        public string MakeSendMessage(string receivedMessage)
        {
            var message = JsonConvert.DeserializeObject <ClientMessage>(receivedMessage);

            var(methodSuccess, sendMessage) = message switch
            {
                CreatePlayerMessage cr => CreatePlayer(cr),
                CloseCreateMessage cl => CloseCreate(cl),
                GetMatchInfoMessage gm => GetMatchInfo(gm),
                GetAllMatchesMessage _ => GetAllMatches(),
                DiceMessage dm => ThrowDice(dm),
                GetStartedMatchMessage gsm => GetStatedMatch(gsm),
                GetRankingMessage gr => GetRanking(gr),
                GetMatchViewImageMessage gmv => GetMatchView(gmv),
                _ => throw new NotImplementedException()
            };

            return(HeaderProtocol.MakeHeader(sendMessage, methodSuccess));
        }
Esempio n. 4
0
        private bool PlayerInfoUpdate()
        {
            using var socket = ConnectServer.CreateSocket((IPAddress)Application.Current.Properties["serverIpAddress"],
                                                          (int)Application.Current.Properties["serverPort"]);
            var requestMethod = new GetMatchInfoMessage(_myPlayerInfo.MatchKey);
            var requestText   = JsonConvert.SerializeObject(requestMethod);

            var(_, result, msg) = Connection.SendAndRecvMessage(requestText, socket, true);

            if (!result)
            {
                var failed = JsonConvert.DeserializeObject <FailedMessage>(msg);
                throw new Exception($"MatchKey Error: {failed.Message}");
            }

            if (_hostPlayersPageMoved)
            {
                return(false);
            }

            _matchInfo = JsonConvert.DeserializeObject <MatchInfo>(msg);
            if (_matchInfo.CreatePlayerClosed)
            {
                Device.BeginInvokeOnMainThread(async() =>
                                               await Navigation.PushAsync(new PlayPage(_myPlayerInfo, _matchInfo)));
                return(false);
            }

            var viewModels = _matchInfo.Players.Select(p => new WaitOtherPlayerViewModel
            {
                IdInfo      = $"{(p.PlayerID == _myPlayerInfo.PlayerID ? "自分 " : "")}ID: {p.PlayerID}",
                PlayerName  = p.PlayerName,
                ImageSource = _playerImages[p.PlayerID - 1]
            });

            PlayersView.ItemsSource = viewModels;
            return(true);
        }