Exemple #1
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系统初始化完成!");
        }
Exemple #2
0
 public ActionResult Index(GameRequestViewModel request)
 {
     game = GameApplication.Instance;
     GameViewModel model = new GameViewModel();
     List<int[]> pointsFrom = new List<int[]>();
     List<int[]> pointsTo = new List<int[]>();
     int drawSize;
     model.clickedPointY = 0;
     model.clickedPointX = 0;
     game.CreateGame(request.GameName, 800, 800, out pointsFrom, out pointsTo, out drawSize);//width, height!!!!!
     model.drawSize = drawSize;
     model.pointFrom = pointsFrom;
     model.pointsTo = pointsTo;
     model.Title = request.GameName;
     model.User = new CurrentUser() { Name = request.UserName, Password = request.UserPassword };
     model.Game = game;
     return View(model);
 }
Exemple #3
0
        public override void OnOperateRequest(byte[] bytes, ClientPeer peer, SendParameters sendParameters)
        {
            JoinRoom joinRoom = PackageHelper.Desirialize <JoinRoom>(bytes);

            GameApplication application = GameApplication.Instance;

            if (application == null)
            {
                return;
            }

            Room room = application.GetRoom(joinRoom.roomID);

            if (room == null)
            {
                return;
            }
            room.JoinRoom(peer as GameClientPeer, joinRoom.userName);
        }
Exemple #4
0
        public void Send(string name, string password, GameApplication gameNow)
        {
            if (game == null)
            {
                game = gameNow;
            }
            else
            {
                if (game != gameNow)
                {
                    throw new ArgumentException("Users chouse different games!");
                }
            }

            var connectionID = Context.ConnectionId;
            bool alreadyExists = Users.Any(x => x.Name == name && x.Password == password);
            if (!alreadyExists)
            {
                Users.Add(new CurrentUser() { Name = name, ConnectionID = connectionID, Password = password });
            }

        }
Exemple #5
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            GameApplication application = GameApplication.Instance;

            if (application == null)
            {
                return;
            }
            BaseHandler handler = application.GetHandler((OperationCode)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);
        }
        public override void OnOperateRequest(byte[] bytes, GameServerPeer peer, SendParameters sendParameters)
        {
            S2SCreateRoom   roomData    = PackageHelper.Desirialize <S2SCreateRoom>(bytes);
            GameApplication application = GameApplication.Instance as GameApplication;

            if (application == null)
            {
                return;
            }
            Room room = application.CreateRoom(roomData.roomID, roomData.members.Count);

            for (int i = 0; i < roomData.members.Count; ++i)
            {
                S2SRoomMember member = roomData.members[i];
                room.userNames.Add(member.userName);
            }

            OperationResponse response = new OperationResponse((byte)S2SOperationCode.CreateRoom);

            response.ReturnCode = (byte)ReturnCode.Success;
            PackageHelper.SetData(response, bytes);
            peer.SendOperationResponse(response, sendParameters);
        }
Exemple #7
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    = null;

            if (operationResponse.Parameters.TryGetValue(0, out p))
            {
                data = p as byte[];
            }
            handler.OnOperationResponse((ReturnCode)operationResponse.ReturnCode, data);
        }
Exemple #8
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    = null;

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