コード例 #1
0
        /// <summary>
        /// 試合への参加ができないようにする
        /// </summary>
        /// <param name="matchKey">部屋名</param>
        public void CloseJoinMatch(string matchKey)
        {
            var sendMsg  = new CloseCreateMessage(matchKey);
            var sendJson = JsonConvert.SerializeObject(sendMsg);

            var(r, recvJson) = SocketManager.SendRecv(sendJson);
            while (!r)
            {
                sendJson      = JsonConvert.SerializeObject(sendMsg);
                (r, recvJson) = SocketManager.SendRecv(sendJson);
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        private void GameStartButtonClicked(object sender, EventArgs e)
        {
            GameStartButton.IsEnabled = false;
            using var socket          = ConnectServer.CreateSocket((IPAddress)Application.Current.Properties["serverIpAddress"],
                                                                   (int)Application.Current.Properties["serverPort"]);
            var requestMethod = new CloseCreateMessage(_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($"CloseCreate Error: {failed.Message}");
            }

            _hostPlayersPageMoved = true;
            Device.BeginInvokeOnMainThread(async() =>
                                           await Navigation.PushAsync(new PlayPage(_myPlayerInfo, _matchInfo)));
        }