示例#1
0
        public override void OnOperationResponse(ReturnCode returnCode, byte[] returnData)
        {
            if (returnCode != ReturnCode.Success)
            {
                return;
            }
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }

            S2SCreateRoom roomData = PackageHelper.Desirialize <S2SCreateRoom>(returnData);

            for (int i = 0; i < roomData.members.Count; ++i)
            {
                S2SRoomMember member     = roomData.members[i];
                ClientInfo    clientInfo = application.GetClientInfo(member.userName);
                if (clientInfo == null)
                {
                    continue;
                }
                Operation.JoinGameServer jgs = new Operation.JoinGameServer();
                jgs.application = "GameServer";
                jgs.ip          = "127.0.0.1";
                jgs.port        = "5056";
                clientInfo.client.SendEvent <Operation.JoinGameServer>(Operation.OperationCode.JoinGameServer, jgs);
            }
        }
示例#2
0
        public override void OnOperateRequest(byte[] bytes, ClientPeer peer, SendParameters sendParameters)
        {
            Operation.UserInfo userInfo = PackageHelper.Desirialize <Operation.UserInfo>(bytes);
            Model.UserInfo     dbUser   = UserManager.GetByUserName(userInfo.username);

            if (dbUser == null)
            {
                return;
            }

            OperationResponse response = new OperationResponse((byte)OperationCode.Login);

            if (dbUser.Password == userInfo.password)
            {
                response.ReturnCode = (short)ReturnCode.Success;
            }
            else
            {
                response.ReturnCode = (short)ReturnCode.Failed;
            }
            LoginSuccessResponse obj = new LoginSuccessResponse();

            obj.userName = userInfo.username;
            PackageHelper.SetData(response, PackageHelper.Serialize <LoginSuccessResponse>(obj));
            peer.SendOperationResponse(response, sendParameters);

            GameApplication application = GameApplication.Instance as GameApplication;

            if (application != null)
            {
                application.AddClientInfo(peer as GameClientPeer, userInfo.username);
            }
        }
示例#3
0
        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }
            application.RemovePeer(this);
        }
示例#4
0
        public override void OnOperateRequest(byte[] bytes, ClientPeer peer, SendParameters sendParameters)
        {
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }

            application.JoinRoom(peer as GameClientPeer);
        }
示例#5
0
        public static void Initialize(GameApplication application)
        {
            log = LogManager.GetCurrentClassLogger();

            log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(application.ApplicationRootPath, "log");

            string   configPath     = Path.Combine(application.BinaryPath, "log4net.config");
            FileInfo configFileInfo = new FileInfo(configPath);

            if (configFileInfo.Exists)
            {
                LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance); // 让Photon知道使用的是哪个日志插件(log4net)
                XmlConfigurator.ConfigureAndWatch(configFileInfo);          // 让log4net读取配置文件
            }

            Log("Debug系统初始化完成!");
        }
示例#6
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }
            BaseHandler handler = application.GetHandler((Operation.OperationCode)operationRequest.OperationCode);

            if (handler == null)
            {
                return;
            }
            byte[] bytes = (byte[])operationRequest.Parameters[0];
            handler.OnOperateRequest(bytes, this, sendParameters);
        }
示例#7
0
文件: Room.cs 项目: zd304/ProjectD
        public void Ready(ClientInfo clientInfo)
        {
            RoomClient c = null;

            if (!clients.TryGetValue(clientInfo.userName, out c))
            {
                return;
            }
            c.ready = true;

            BroadcastRoom();

            if (clients.Count >= NormalRoomMaxClient)
            {
                foreach (var kv in clients)
                {
                    RoomClient client = kv.Value;
                    if (!client.ready)
                    {
                        return;
                    }
                }
                GameApplication application = GameApplication.Instance as GameApplication;
                if (application == null)
                {
                    return;
                }

                Operation.S2SCreateRoom roomData = new Operation.S2SCreateRoom();
                roomData.roomID = roomID;

                foreach (var kv in clients)
                {
                    RoomClient client = kv.Value;

                    Operation.S2SRoomMember member = new Operation.S2SRoomMember();
                    member.userName = client.client.userName;
                    roomData.members.Add(member);
                }
                var serverPeer = application.GetMinLoadingServerPeer();
                serverPeer.DoRequest <Operation.S2SCreateRoom>(Operation.S2SOperationCode.CreateRoom, roomData);
            }
        }
示例#8
0
        public override void OnOperateRequest(byte[] bytes, ClientPeer peer, SendParameters sendParameters)
        {
            ReadyData readyData = PackageHelper.Desirialize <ReadyData>(bytes);

            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }

            Room       room       = application.GetRoom(readyData.roomID);
            ClientInfo clientInfo = application.GetClientInfo(peer as GameClientPeer);

            if (room != null && clientInfo != null)
            {
                room.Ready(clientInfo);
            }
        }
示例#9
0
文件: Room.cs 项目: zd304/ProjectD
        public void RemoveClient(ClientInfo clientInfo)
        {
            clientInfo.roomID = 0;
            RoomClient c = null;

            if (!clients.TryGetValue(clientInfo.userName, out c))
            {
                return;
            }
            clients.Remove(clientInfo.userName);

            BroadcastRoom();

            if (clients.Count == 0)
            {
                GameApplication application = GameApplication.Instance as GameApplication;
                if (application != null)
                {
                    application.RemoveRoom(this);
                }
            }
        }
示例#10
0
        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }
            S2SBaseHandler handler = application.GetS2SHandler((S2SOperationCode)operationResponse.OperationCode);

            if (handler == null)
            {
                return;
            }
            byte[] data = null;
            object p;

            if (operationResponse.Parameters.TryGetValue(0, out p))
            {
                data = p as byte[];
            }
            handler.OnOperationResponse((ReturnCode)operationResponse.ReturnCode, data);
        }
示例#11
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }
            S2SBaseHandler handler = application.GetS2SHandler((S2SOperationCode)operationRequest.OperationCode);

            if (handler == null)
            {
                return;
            }
            byte[] data = null;
            object p;

            if (operationRequest.Parameters.TryGetValue(0, out p))
            {
                data = p as byte[];
            }
            handler.OnOperateRequest(data, this, sendParameters);
        }
示例#12
0
        protected override void OnEvent(IEventData eventData, SendParameters sendParameters)
        {
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }
            S2SBaseHandler handler = application.GetS2SHandler((S2SOperationCode)eventData.Code);

            if (handler == null)
            {
                return;
            }
            byte[] data = null;
            object p;

            if (eventData.Parameters.TryGetValue(0, out p))
            {
                data = p as byte[];
            }
            handler.OnEvent(data);
        }