Esempio n. 1
0
        public ActionResult RuleTest()
        {
            var sid = PlayRoomsManager.MakeTempSession(RuleTestHandler.ROOM_ID_PREFIX);

            PlayRoomsManager.GetOrCreate(sid);
            ViewBag.RoomId = sid;
            return(View());
        }
Esempio n. 2
0
        public ActionResult Practice(string id)
        {
            var rule = id;
            var sid  = PlayRoomsManager.MakeTempSession(PracticeHandler.ROOM_ID_PREFIX);

            PlayRoomsManager.GetOrCreate(sid, rule);
            ViewBag.RoomId = sid;
            return(View());
        }
Esempio n. 3
0
        public override void OnOpen()
        {
            Debug.WriteLine(WebSocketContext.Headers);
            lock (lockObj)
            {
                AllClients.Add(this);

                // クエリストリングを自力で解析
                playerName = this.WebSocketContext.QueryString["name"];

                var mc = Regex.Matches(this.WebSocketContext.RequestUri.OriginalString, @"/play/(A|B)/([\-A-Z0-9]*)\?");
                if (mc.Count > 0)
                {
                    rule      = mc[0].Groups[1].Success ? mc[0].Groups[1].Value.ToString() : "A";
                    sessionId = mc[0].Groups[2].Success ? mc[0].Groups[2].Value.ToString() : "1";
                }

                room = PlayRoomsManager.GetOrCreate(sessionId, rule);
                var key = this.WebSocketContext.CreatePlayerKey(playerName);

                pAdapter = room.FindRemotePlayer(key) as GamePlayerAdapter;
                if (pAdapter != null && !pAdapter.IsConnected)
                {
                    // 再接続とみなす
                    logger.Debug("Reconnect [{0}] sessionId={1}", playerName, sessionId);
                    pAdapter.Reconnect(playerName, (str) => Send(str));
                }
                else
                {
                    // すでにプレイ中なら切断する
                    logger.Debug("Connect [{0}] sessionId={1}", playerName, sessionId);
                    if (room == null || room.NumOfRounds > 0)
                    {
                        this.Close(); return;
                    }

                    pAdapter = new GamePlayerAdapter(room, playerName, (str) => Send(str));
                    room.AddPlayer(key, pAdapter);
                }
            }
        }