protected override void OnLoad(object[] args) { // By default we want the menu to not be visible menu.Visible = false; // Hook into window focus event so we can // toggle the menu when needed Window.OnFocusChanged += Window_OnFocusChanged; // Attempt to grab the server address and playername // from the args. IPEndPoint endPoint; if (args.Length != 2 || (endPoint = args[0] as IPEndPoint) == null || (playerName = args[1] as string) == null) { throw new ArgumentException("MultiplayerScreen requires a IPEndPoint and a string argument."); } // Attempt to connect to the server NetDenialReason?denialReason; if (TryConnect(endPoint, out denialReason)) { // Hook into disconnected event so we can handle // unexpected disconnections client.OnDisconnected += Client_OnDisconnected; // Hook into packet receiving client.AddPacketHook(OnCustomPacket); // Hook into component events objectComponent.OnCreatableInstantiated += ObjectComponent_OnCreatableInstantiated; objectComponent.OnCreatableDestroyed += ObjectComponent_OnCreatableDestroyed; // Show the loading bar loadingBar.ClearAndShow(); // Create the world and hook into it's events World = new MPWorld(Renderer); hud.SetWorld(World); // Send our information to the server netPlayerComponent.SendClientInfo(playerName); // Clear the chat chat.Clear(); } else { // If we fail to connect, just kickback to the MainMenu with a message. Window.SwitchScreen("MainMenu", "Failed to connect to server: " + denialReason.Value.ToString()); } base.OnLoad(args); }
void R_UnloadWorld(NetConnection server, NetBuffer data, ushort numArgs) { // Unload the world UnloadWorld(); // Kickback the UI to a loading state loadingBar.ClearAndShow(); if (!StaticGui.ShowBackground) { Window.StaticGui.ShowRandomBackgroundImage(); } StaticGui.ShowBackground = true; // Generate the new world object in preparation // for the new data from the server. World = new MPWorld(Renderer); hud.SetWorld(World); }