Esempio n. 1
0
        public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            // get parameter
            var      serial = (string)operationRequest.Parameters[(byte)ParameterCode.Serial];
            Actor    actor  = ServerApp.instance.actorManager.GetActorFromGuid(peer.peerGuid);
            CellRoom room   = ServerApp.instance.cellManager.TryGetRoomBySerial(serial);
            // create response.
            OperationResponse response = new OperationResponse(operationRequest.OperationCode);

            if (room == null)
            {
                response.ReturnCode   = (short)ResultCode.Failed;
                response.DebugMessage = "The room was not exist.";
            }
            else
            {
                // try to join room.
                if (room.Join(actor.memberID))
                {
                    response.ReturnCode   = (short)ResultCode.Success;
                    response.DebugMessage = "JoinRoom Success";
                    ServerApp.Logger.InfoFormat("Actor {0} JoinRoom serial: {1}", actor.memberID, serial);

                    peer.SendOperationResponse(response, sendParameters);
                }
                else
                {
                    response.ReturnCode   = (short)ResultCode.Failed;
                    response.DebugMessage = "The room is full.";
                    peer.SendOperationResponse(response, sendParameters);
                }
            }
        }
Esempio n. 2
0
        public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            Actors.Actor actor = ServerApp.instance.actorManager.GetActorFromGuid(peer.peerGuid);
            CellRoom     room  = ServerApp.instance.cellManager.TryGetRoomByIndex(actor.roomIndex);

            room.AddFinishCounter();
        }
Esempio n. 3
0
        public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            // Get parameter
            Actor    actor = ServerApp.instance.actorManager.GetActorFromGuid(peer.peerGuid);
            CellRoom room  = ServerApp.instance.cellManager.TryGetRoomByIndex(actor.roomIndex);

            room.ChangeReady(peer.peerGuid);
        }
Esempio n. 4
0
        public static void SendEvent(CellRoom room)
        {
            EventData eventData = new EventData((byte)EventCode.GameEnter,
                                                new Dictionary <byte, object>());

            foreach (CellRoom.ActorInfo roomActor in room.actorList)
            {
                Actor      actor = ServerApp.instance.actorManager.GetActorFromMemberID(roomActor.memberID);
                ServerPeer peer  = ServerApp.instance.actorManager.TryGetPeer(actor.guid);

                peer.SendEvent(eventData, new SendParameters());
            }
        }
Esempio n. 5
0
        public static void SendEvent(CellRoom room)
        {
            // Get actor list from room.
            List <CellRoom.ActorInfo> actorList = room.actorList;
            // conversion roomActorList
            List <RoomActorData> roomActorList = new List <RoomActorData>();

            for (int i = 0; i < actorList.Count; i++)
            {
                RoomActorData actorData = new RoomActorData();
                actorData.memberID = actorList[i].memberID;
                actorData.isReady  = actorList[i].isReady;
                roomActorList.Add(actorData);
            }

            // Create transfer data
            RoomInfoData roomData = new RoomInfoData();

            roomData.serial    = room.SerialNum;
            roomData.actorList = roomActorList;

            // Serialize roominfodata.
            byte[]       roomInfoDataByte = ProtoBufTool.Serialize(roomData);
            RoomInfoData testData         = ProtoBufTool.Deserialize <RoomInfoData>(roomInfoDataByte);

            ServerApp.Logger.Info(testData.serial);

            // push data to actors
            for (int i = 0; i < actorList.Count; i++)
            {
                // get peer
                Actor      actor = ServerApp.instance.actorManager.GetActorFromMemberID(actorList[i].memberID);
                ServerPeer peer  = ServerApp.instance.actorManager.TryGetPeer(actor.guid);

                // generate event data.
                var eventDict = new Dictionary <byte, object>();
                eventDict.Add((byte)ParameterCode.RoomInfoData, roomInfoDataByte);

                EventData eventData = new EventData((byte)EventCode.RoomUpdate);
                eventData.Parameters = eventDict;

                peer.SendEvent(eventData, new SendParameters());
            }
        }
Esempio n. 6
0
        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
            Actor actor = _server.actorManager.GetActorFromGuid(peerGuid);

            ServerApp.Logger.InfoFormat("[ServerPeer] Actor {0} disconnect", actor.memberID);

            if (actor.roomIndex >= 0)
            {
                // actor in room , must remove from room's actor list.
                CellRoom room = ServerApp.instance.cellManager.TryGetRoomByIndex(actor.roomIndex);
                room.Quit(actor.memberID);
            }
            else if (actor.roomIndex == -1)
            {
                // actor in lobby, must remove from lobby's actor list.
                ServerApp.instance.cellManager.Lobby.Remove(actor.memberID);
            }

            _server.actorManager.ActorOffline(peerGuid);
        }
Esempio n. 7
0
        public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            // Create response.
            OperationResponse response = new OperationResponse(operationRequest.OperationCode);

            // Try to create room.
            Actors.Actor actor = ServerApp.instance.actorManager.GetActorFromGuid(peer.peerGuid);
            CellRoom     room  = ServerApp.instance.cellManager.CreateRoom(actor.memberID);

            if (room == null)
            {
                response.ReturnCode   = (short)ResultCode.Failed;
                response.DebugMessage = "CreateRoom failed.";
            }
            else
            {
                ServerApp.Logger.InfoFormat("Acotr {0} create room index: {1}", actor.memberID, room.SerialNum);

                response.ReturnCode   = (short)ResultCode.Success;
                response.DebugMessage = "CreateRoom Success.";
            }

            peer.SendOperationResponse(response, sendParameters);
        }