/// <summary> /// Toggles the server between advertisement mode. Advertisement would /// add increased rates for the servers /// </summary> /// <param name="args">Arguments</param> static void ToggleAdvertisment(string[] args) { ShowAdvertisment ^= true; Console.WriteLine("Advertisment is: {0}", (ShowAdvertisment) ? "shown" : "hidden"); lock (ServerManager2.Instance.server) { foreach (KeyValuePair <byte, ServerInfo2> b in ServerManager2.Instance.server) { if (b.Value.client != null && b.Value.client.IsConnected == true) { try { SMSG_SETRATES spkt = new SMSG_SETRATES(); spkt.IsAdDisplayed = (ShowAdvertisment) ? (byte)1 : (byte)0; b.Value.client.Send((byte[])spkt); } catch (Exception) { Trace.TraceWarning("Error notifying server"); } } } } }
// 0x0001 public void CM_WORLDINSTANCE(CMSG_WORLDINSTANCE cpkt) { ServerInfo2 info = null; byte error = 0; byte WorldId = 0; try { //socket.RemoteEndPoint. IPEndPoint IPEndPoint = (IPEndPoint)socket.RemoteEndPoint; WorldId = cpkt.WorldId; //SERVER DOES NOT EXISTS if (!ServerManager2.Instance.server.TryGetValue(WorldId, out info)) { error = 3; } //IF PROOF IS VALID else if (info.proof != cpkt.Proof) { error = 1; } //CHECK IF SERVER IS ALIVE else if (info.client != null && info.client.IsConnected && cpkt.IsReconnected == 0) { error = 2; } //IF EVERYTHING IS OKAY else { this.WorldId = WorldId; info.GenerateKey(); info.client = this; info.MaxPlayers = cpkt.MaximumPlayers; info.Players = 0; info.InMaintainceMode = false; info.IP = IPEndPoint.Address; info.Port = cpkt.Port; info.RequiredAge = cpkt.RequiredAge; Console.WriteLine("world connection established"); if (cpkt.IsReconnected == 0) { Singleton.Database.ClearWorldSessions(this.WorldId); } SMSG_SETRATES spkt = new SMSG_SETRATES(); spkt.IsAdDisplayed = Managers.ConsoleCommands.ShowAdvertisment ? (byte)1 : (byte)0; this.Send((byte[])spkt); } } finally { Thread.Sleep(500); SMSG_WORLDINSTANCEACK spkt = new SMSG_WORLDINSTANCEACK(); spkt.Result = error; if (error == 0) { spkt.NextKey = info.KEY; } this.Send((byte[])spkt); } }