예제 #1
0
        public static void HandleMessage(Byte[] msgData, GameSession session, GamePlayer client)
        {
            using(MemoryStream stream = new MemoryStream(msgData))
            {
                BaseMessage msg = Serializer.Deserialize<BaseMessage>(stream);

                switch((MessageType)msg.messageType)
                {
                    case MessageType.LoginRequest:
                        {
                            LoginRequest loginMsg = (LoginRequest) msg;

                            int status = LoginManager.GetInstance().ValidateCredentials(new User.GCUser.LoginInfo(loginMsg.username), loginMsg.password);

                            LoginResponse response = new LoginResponse() { success = (status == 0) };
                            client.DispatchMessage(response);
                            break;
                        }
                    case MessageType.ChatMessage:
                        {
                            session.SendToPlayers(msgData);
                            break;
                        }
                    case MessageType.CreateUserRequest:
                        {
                            CreateUserRequest createUserMessage = (CreateUserRequest)msg;

                            int status = (int)DBEnum.DBResponseCodes.SUCCESS;//LoginManager.GetInstance().CreateUser(new User.GCUser.LoginInfo(createUserMessage.mUsername), createUserMessage.mPassword);

                            CreateUserResponse response = new CreateUserResponse() { success = ((int)DBEnum.DBResponseCodes.SUCCESS == status) };
                            client.DispatchMessage(response);
                            break;
                        }
                    case MessageType.Heartbeat:
                    default:
                        {
                            break;
                        }
                }
            }
        }
예제 #2
0
        public void JoinGameSession(/*type requested, matchmaking criteria, etc*/)
        {
            // Leave any pre-existing game session
            if(null != mGameSession)
            {
                QuitGameSession();
            }

            // Find new game session
            mGameSession = mContext.FindGameSession();

            //GCAssert(null != mGameSession);

            // Tie the connection between session and player
            mGameSession.AddPlayer(this);

            ChatMessage msg = new ChatMessage()
            {
                sender = "Server",
                message = "You have joined the Game Session."
            };
            DispatchMessage(msg);
        }
예제 #3
0
        public void QuitGameSession()
        {
            mGameSession.RemovePlayer(this);
            mGameSession = null;

            // Tell client socket that they have quit the game? maybe
        }
예제 #4
0
 private GameSession _CreateNewGameSession()
 {
     GameSession gs = new GameSession();
     mGameSessions.Add(gs);
     return gs;
 }