public PPDServer(int port, WebManager webManager, RoomInfo roomInfo, ITimerManager timerManager, string logDir, string[] allowedModIds) { RoomInfo = roomInfo; WebManager = webManager; TimerManager = timerManager; AllowedModIds = allowedModIds; if (!String.IsNullOrEmpty(logDir)) { Logger = new Logger(logDir, String.Format("{0}.log", port)); } contexts = new List <ServerContextBase>(); afterPushContexts = new List <ServerContextBase>(); afterPopContexts = new List <ServerContextBase>(); hostHandledData = new Queue <NetworkData>(); contextChains = new Dictionary <ServerContextBase, ServerContextBase>(); userLastUpdatedAt = new Dictionary <int, DateTime>(); delayedDisconnects = new Dictionary <int, DateTime>(); byteReader = new TcpByteReader(); byteReader.ByteReaded += byteReader_ByteReaded; host = new Host { Port = port }; host.ReadClient += host_ReadClient; host.Closed += host_Closed; }
public override bool Load() { clientHandledData = new Queue <NetworkData>(); client = Param["Client"] as Client; byteReader = Param["ByteReader"] as TcpByteReader; client.Closed += client_Closed; byteReader.ByteReaded += TcpByteReader_ByteReaded; gameRule = Param["GameRule"] as GameRule; userList = new ChangableList <User>(Param["Users"] as User[]); var songInformation = Param["SongInformation"] as SongInformation; var difficulty = (Difficulty)Param["Difficulty"]; var allowedModList = (AllowedModList)Param["AllowedModList"]; selfUser = Param["Self"] as User; userPlayStateList = new ChangableList <UserPlayState>(); userPlayStateList.ItemChanged += userPlayStateList_ItemChanged; userScoreListComponent = new UserScoreListComponent(device, ResourceManager) { Position = new SharpDX.Vector2(680, 45) }; itemManagerComponent = new ItemManagerComponent(device, ResourceManager, gameRule) { Position = new SharpDX.Vector2(682, 420) }; itemOverrayComponent = new ItemOverrayComponent(device, ResourceManager, itemManagerComponent); itemOverrayComponent.ItemSet += itemOverrayComponent_ItemSet; selfPlayState = new UserPlayState { User = selfUser }; foreach (User user in userList) { var userPlayState = new UserPlayState { User = user }; if (user == selfUser) { userScoreListComponent.AddSelfUser(selfPlayState, itemManagerComponent); } else { userPlayStateList.Add(userPlayState); userScoreListComponent.AddUser(userPlayState); } } userScoreListComponent.AddFinish(); black = new RectangleComponent(device, ResourceManager, PPDColors.Black) { RectangleHeight = 450, RectangleWidth = 800, Alpha = 0, Hidden = true }; // メインゲーム用のパラメータの準備 gameutility = new PPDGameUtility { SongInformation = songInformation, Difficulty = difficulty, DifficultString = songInformation.GetDifficultyString(difficulty), Profile = ProfileManager.Instance.Default, AutoMode = AutoMode.None, SpeedScale = 1, Random = false, MuteSE = (bool)Param["MuteSE"], Connect = (bool)Param["Connect"], IsDebug = true, GodMode = true, CanApplyModCallback = m => allowedModList.IsAllowed(m.FileHashString) || !m.ContainsModifyData }; GameInterfaceBase cgi = new GameInterface(device) { Sound = Sound, PPDGameUtility = gameutility, ResourceManager = ResourceManager }; cgi.Load(); pauseMenu = null; if (selfUser.IsLeader) { pauseMenu = new PauseMenu(device) { Sound = Sound, ResourceManager = ResourceManager }; pauseMenu.Load(); pauseMenu.Resumed += pauseMenu_Resumed; pauseMenu.Returned += pauseMenu_Returned; } config = new MainGameConfig(itemManagerComponent); mainGameComponent = new MainGameComponent(device, GameHost, ResourceManager, Sound, this, gameutility, cgi, new MarkImagePaths(), null, pauseMenu, config, songInformation.StartTime, songInformation.StartTime) { PauseMovieWhenPause = false }; filterSprite = new SpriteObject(device); mainGameComponent.Finished += mainGameComponent_Finished; mainGameComponent.Drawed += mainGameComponent_Drawed; mainGameComponent.ScoreChanged += mainGameComponent_ScoreChanged; mainGameComponent.LifeChanged += mainGameComponent_LifeChanged; mainGameComponent.EvaluateChanged += mainGameComponent_EvaluateChanged; mainGameComponent.ComboChanged += mainGameComponent_ComboChanged; mainGameComponent.Initialize(fadeOut, fadeOut, new Dictionary <string, object> { { "MultiItemComponent", itemManagerComponent } }); this.AddChild(black); shouldDisposeItem.AddRange(new GameComponent[] { userScoreListComponent, itemManagerComponent, itemOverrayComponent, mainGameComponent, filterSprite, pauseMenu }); ConnectExpansion(); client.Write(MessagePackSerializer.Serialize(new MainGameLoadedNetworkData())); return(true); }
public override bool Load() { PPDFramework.Web.WebModInfo[] webMods = null; Action[] actions = { () => { webMods = PPDFramework.Web.WebManager.Instance.GetMods(); }, PPDScoreManager.Manager.Initialize, }; Parallel.ForEach(actions, (action) => action()); allowedModList = new AllowedModList { WebMods = webMods }; logger = new Logger(String.Format("{0}.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"))); Sound.AddSound(notifySoundPath); version = FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(this.GetType()).Location).FileVersion; userList = new ChangableList <User>(); userList.ItemChanged += userList_ItemChanged; movieManager = new MovieManager(device, GameHost); movieManager.MovieChanged += MovieManager_MovieChanged; movieManager.MovieChangeFailed += MovieManager_MovieChangeFailed; clientHandledData = new Queue <NetworkData>(); selfUser = new User { Name = PPDFramework.Web.WebManager.Instance.CurrentUserName, AccountId = PPDFramework.Web.WebManager.Instance.CurrentAccountId, CurrentState = UserState.NotReady, Color = RandomColorGenerator.GetColor(), IsSelf = true, IsHost = (bool)this.Param["AsHost"] }; this.AddChild(gameResultComponent = new GameResultComponent(device, GameHost, ResourceManager, Sound)); this.AddChild(leftMenu = new LeftMenu(device, GameHost, ResourceManager, Sound, movieManager, selfUser, userList, allowedModList)); leftMenu.SongSelected += leftMenu_SongSelected; leftMenu.ShowResult += leftMenu_ShowResult; leftMenu.UpdateScoreDB += leftMenu_UpdateScoreDB; leftMenu.RuleChanged += leftMenu_RuleChanged; leftMenu.TryToPlayGame += leftMenu_TryToPlayGame; leftMenu.ChangeLeader += leftMenu_ChangeLeader; leftMenu.KickUser += leftMenu_KickUser; this.AddChild(textBox = new DxTextBox(device, GameHost, ResourceManager)); this.AddChild((chatComponent = new ChatComponent(device, ResourceManager, GameHost) { Position = new SharpDX.Vector2(430, 0) })); this.AddChild(userListComponent = new UserListComponent(device, ResourceManager) { Position = new SharpDX.Vector2(10, 10) }); PictureObject bottom; this.AddChild(bottom = new PictureObject(device, ResourceManager, Utility.Path.Combine("menu_bottom.png")) { Position = new SharpDX.Vector2(0, 421) }); bottom.AddChild(new PictureObject(device, ResourceManager, Utility.Path.Combine("bottom_triangle.png")) { Position = new SharpDX.Vector2(7, 7) }); bottom.AddChild(new TextureString(device, Utility.Language["Menu"], 16, PPDColors.White) { Position = new SharpDX.Vector2(30, 5) }); bottom.AddChild(new PictureObject(device, ResourceManager, Utility.Path.Combine("bottom_circle.png")) { Position = new SharpDX.Vector2(157, 7) }); bottom.AddChild(stateString = new TextureString(device, Utility.Language["ChangeReadyState"], 16, PPDColors.White) { Position = new SharpDX.Vector2(180, 5) }); this.AddChild((bgd = new BackGroundDisplay(device, ResourceManager, "skins\\PPDMulti_BackGround.xml", "Menu"))); focusManager = new FocusManager(); focusManager.Focus(chatComponent); userList.Add(selfUser); chatComponent.Inputed += chatComponent_Inputed; textBox.LostFocused += textBox_LostFocused; leftMenu.Closed += leftMenu_Closed; if (selfUser.IsHost) { WebManager webManager = null; if (this.Param.ContainsKey("WebManager")) { webManager = this.Param["WebManager"] as WebManager; } RoomInfo roomInfo = null; if (this.Param.ContainsKey("RoomInfo")) { roomInfo = this.Param["RoomInfo"] as RoomInfo; } server = new PPDServer((int)Param["Port"], webManager, roomInfo, GameHost); server.FailedToCreateRoom += server_FailedToCreateRoom; client = new Client { Address = "127.0.0.1", Port = (int)Param["Port"] }; timer = new Timer(state => { server.Update(); }, null, 0, 1); } else { client = new Client { Address = (string)Param["IP"], Port = (int)Param["Port"] }; } client.Closed += client_Closed; client.Read += client_Read; byteReader = new TcpByteReader(); byteReader.ByteReaded += TcpByteReader_ByteReaded; if (server != null) { server.Start(); } client.Start(); if (client.HasConnection) { // send login data client.Write(MessagePackSerializer.Serialize(new AddUserNetworkData { UserName = selfUser.Name, AccountId = selfUser.AccountId, State = selfUser.CurrentState, Version = version })); } else { chatComponent.AddSystemMessage(Utility.Language["CannotConnectToHost"]); } // load SongInformation.All.ToArray(); return(true); }