public static NetMessage OnMessageFromNewClient(NetMessage m) { if (Network.isServer) { if (m is NMRequestJoin) { if (DuckNetwork.inGame) { return((NetMessage) new NMGameInProgress()); } NMRequestJoin nmRequestJoin = m as NMRequestJoin; // DevConsole.Log(DCSection.DuckNet, "|DGYELLOW|Join attempt from " + nmRequestJoin.name, -1); NMVersionMismatch.Type code = DuckNetwork.CheckVersion(nmRequestJoin.id); if (code != NMVersionMismatch.Type.Match) { // DevConsole.Log(DCSection.DuckNet, "|DGYELLOW|" + nmRequestJoin.name + " had a version mismatch.", -1); // return (NetMessage)new NMVersionMismatch(code, DG.version); return((NetMessage) new NMVersionMismatch(code, Assembly.GetEntryAssembly().GetName().Version.ToString())); } Type methodtype = typeof(DuckNetwork); MethodInfo createProfile = methodtype.GetMethod("CreateProfile", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); // Profile profile = DuckNetwork.CreateProfile(m.connection, nmRequestJoin.name, -1, (InputProfile)null, nmRequestJoin.hasCustomHats, nmRequestJoin.wasInvited, false); Profile profile = (Profile)createProfile.Invoke(null, new object[] { m.connection, nmRequestJoin.name, -1, (InputProfile)null, nmRequestJoin.hasCustomHats, nmRequestJoin.wasInvited, false }); if (profile == null) { // DevConsole.Log(DCSection.DuckNet, "|DGYELLOW|" + nmRequestJoin.name + " could not join, server is full.", -1); return((NetMessage) new NMServerFull()); } profile.flippers = nmRequestJoin.flippers; profile.networkStatus = DuckNetStatus.WaitingForLoadingToBeFinished; _core.status = DuckNetStatus.Connected; TeamSelect2Edits.OnNetworkConnecting(profile); DuckNetwork.SendNewProfile(profile, m.connection, false); // More slots so we need bigger method to handle them Send.Message(new NMChangeSlotsEdits((byte)DuckNetwork.profiles[0].slotType, (byte)DuckNetwork.profiles[1].slotType, (byte)DuckNetwork.profiles[2].slotType, (byte)DuckNetwork.profiles[3].slotType, (byte)DuckNetwork.profiles[4].slotType, (byte)DuckNetwork.profiles[5].slotType, (byte)DuckNetwork.profiles[6].slotType, (byte)DuckNetwork.profiles[7].slotType), m.connection); TeamSelect2.SendMatchSettings(m.connection, true); return((NetMessage)null); } if (m is NMMessageIgnored) { return((NetMessage)null); } } else { if (m is NMRequestJoin) { // DevConsole.Log(DCSection.DuckNet, "|DGYELLOW|Another computer has requested a matchmaking connection.", -1); return((NetMessage) new NMGameInProgress()); } if (m is NMMessageIgnored) { return((NetMessage)null); } } return((NetMessage) new NMMessageIgnored()); }
public override void Draw() { if (this._downloadModsMenu.open) { this._downloadModsMenu.DoDraw(); } if (this.open) { this.scrollBarTop = (int)((double)this._box.y - (double)this._box.halfHeight + 1.0 + 16.0); this.scrollBarBottom = (int)((double)this._box.y + (double)this._box.halfHeight - 1.0 - 16.0); this.scrollBarScrollableHeight = this.scrollBarBottom - this.scrollBarTop; if (this.fixView) { Layer.HUD.camera.width *= 2f; Layer.HUD.camera.height *= 2f; this.fixView = false; } DuckGame.Graphics.DrawRect(new Vec2(this._box.x - this._box.halfWidth, this._box.y - this._box.halfHeight), new Vec2((float)((double)this._box.x + (double)this._box.halfWidth - 12.0 - 2.0), this._box.y + this._box.halfHeight), Color.Black, new Depth(0.4f)); DuckGame.Graphics.DrawRect(new Vec2((float)((double)this._box.x + (double)this._box.halfWidth - 12.0), this._box.y - this._box.halfHeight), new Vec2(this._box.x + this._box.halfWidth, this._box.y + this._box.halfHeight), Color.Black, new Depth(0.4f)); Rectangle r = this.ScrollBarBox(); DuckGame.Graphics.DrawRect(r, this._draggingScrollbar || r.Contains(Mouse.position) ? Color.LightGray : Color.Gray, new Depth(0.5f)); if (this._lobbies.Count == 0) { this._fancyFont.Draw("No games found!", new Vec2(this._box.x - this._box.halfWidth + 10f, (float)((double)this._box.y - (double)this._box.halfHeight + 0.0) + 2f), Color.Yellow, new Depth(0.5f)); } this._lobbies = this._lobbies.OrderByDescending <UIServerBrowser.LobbyData, bool>((Func <UIServerBrowser.LobbyData, bool>)(x => x.canJoin)).ToList <UIServerBrowser.LobbyData>(); for (int index1 = 0; index1 < this._maxLobbiesToShow; ++index1) { int index2 = this._scrollItemOffset + index1; if (index2 < this._lobbies.Count) { float x1 = this._box.x - this._box.halfWidth; float y = this._box.y - this._box.halfHeight + (float)(36 * index1); if (this._hoverIndex == index2) { DuckGame.Graphics.DrawRect(new Vec2(x1, y), new Vec2((float)((double)x1 + (double)this._box.width - 14.0), y + 36f), Color.White * 0.6f, new Depth(0.4f)); } else if ((index2 & 1) != 0) { DuckGame.Graphics.DrawRect(new Vec2(x1, y), new Vec2((float)((double)x1 + (double)this._box.width - 14.0), y + 36f), Color.White * 0.1f, new Depth(0.4f)); } UIServerBrowser.LobbyData lobby = this._lobbies[index2]; if (lobby != null) { this._noImage.texture = this.defaultImage; this._noImage.scale = new Vec2(1f, 1f); List <Tex2D> tex2DList = new List <Tex2D>(); string name = lobby.name; string text1 = "|WHITE||GRAY|\n"; if (lobby.workshopItems.Count > 0) { WorkshopItem workshopItem1 = lobby.workshopItems[0]; if (workshopItem1.data != null) { lobby.workshopItems = lobby.workshopItems.OrderByDescending <WorkshopItem, int>((Func <WorkshopItem, int>)(x => x.data == null ? 0 : x.data.votesUp)).ToList <WorkshopItem>(); if (!lobby.downloadedWorkshopItems) { lobby.hasFirstMod = true; lobby.hasRestOfMods = true; bool flag = true; foreach (WorkshopItem workshopItem2 in lobby.workshopItems) { ulong id = workshopItem2.id; if (ModLoader.accessibleMods.FirstOrDefault <Mod>((Func <Mod, bool>)(x => (long)x.configuration.workshopID == (long)id)) == null) { if (flag) { lobby.hasFirstMod = false; } else { lobby.hasRestOfMods = false; } } flag = false; } lobby.downloadedWorkshopItems = true; } string str1 = !lobby.hasFirstMod ? "|RED|Requires " + workshopItem1.name : "|DGGREEN|Requires " + workshopItem1.name; string str2 = lobby.hasRestOfMods ? "|DGGREEN|" : "|RED|"; if (lobby.workshopItems.Count == 2) { str1 = str1 + str2 + " +" + (lobby.workshopItems.Count - 1).ToString() + " other mod."; } else if (lobby.workshopItems.Count > 2) { str1 = str1 + str2 + " +" + (lobby.workshopItems.Count - 1).ToString() + " other mods."; } text1 = str1 + "\n|GRAY|"; if (!UIServerBrowser._previewMap.ContainsKey(workshopItem1.id)) { if (workshopItem1.data.previewPath != null) { if (workshopItem1.data.previewPath != "") { try { WebClient webClient = new WebClient(); string str3 = this.PreviewPathForWorkshopItem(workshopItem1.id); DuckFile.CreatePath(str3); if (System.IO.File.Exists(str3)) { DuckFile.Delete(str3); } webClient.DownloadFileAsync(new Uri(workshopItem1.data.previewPath), str3); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.Completed); UIServerBrowser._clientMap[(object)webClient] = workshopItem1.id; } catch (Exception ex) { } } } UIServerBrowser._previewMap[workshopItem1.id] = (Tex2D)null; } else { Tex2D preview = UIServerBrowser._previewMap[workshopItem1.id]; if (preview != null) { tex2DList.Add(preview); } } } } if (lobby.wallMode == "1") { text1 += "Wall Mode. "; } if (lobby.requiredWins != "") { text1 = text1 + "First to " + lobby.requiredWins.ToString() + " "; } if (lobby.restsEvery != "") { text1 = text1 + "rests every " + lobby.restsEvery.ToString() + ". "; } if (lobby.customLevels != "" && lobby.customLevels != "0") { text1 = text1 + lobby.customLevels.ToString() + " Custom Levels. "; } DuckGame.Graphics.DrawRect(new Vec2(x1 + 2f, y + 2f), new Vec2((float)((double)x1 + 36.0 - 2.0), (float)((double)y + 36.0 - 2.0)), Color.Gray, new Depth(0.5f), false, 2f); if (tex2DList.Count > 0) { Vec2 zero = Vec2.Zero; for (int index3 = 0; index3 < 4; ++index3) { if (index3 < tex2DList.Count) { this._noImage.texture = tex2DList[index3]; if (tex2DList.Count > 1) { this._noImage.scale = new Vec2(16f / (float)this._noImage.texture.width); } else { this._noImage.scale = new Vec2(32f / (float)this._noImage.texture.width); } if (this._noImage.texture.width != this._noImage.texture.height) { if (this._noImage.texture.width > this._noImage.texture.height) { this._noImage.scale = new Vec2(32f / (float)this._noImage.texture.height); DuckGame.Graphics.Draw(this._noImage, x1 + 2f + zero.x, y + 2f + zero.y, new Rectangle((float)(this._noImage.texture.width / 2 - this._noImage.texture.height / 2), 0.0f, (float)this._noImage.texture.height, (float)this._noImage.texture.height), new Depth(0.5f)); } else { DuckGame.Graphics.Draw(this._noImage, x1 + 2f + zero.x, y + 2f + zero.y, new Rectangle(0.0f, 0.0f, (float)this._noImage.texture.width, (float)this._noImage.texture.width), new Depth(0.5f)); } } else { DuckGame.Graphics.Draw(this._noImage, x1 + 2f + zero.x, y + 2f + zero.y, new Depth(0.5f)); } zero.x += 16f; if ((double)zero.x >= 32.0) { zero.x = 0.0f; zero.y += 16f; } } } } else { DuckGame.Graphics.Draw(this._noImage, x1 + 2f, y + 2f, new Depth(0.5f)); } string text2 = name; if (lobby.maxPlayers != "") { text2 = text2 + " (" + lobby.lobby.users.Count.ToString() + "/" + lobby.numSlots.ToString() + ")"; } if (!lobby.canJoin) { string str = text2 + " |DGRED|("; if (lobby.version != DG.version) { switch (DuckNetwork.CheckVersion(lobby.version)) { case NMVersionMismatch.Type.Older: str += "They have an older version."; break; case NMVersionMismatch.Type.Newer: str += "They have a newer version."; break; default: str += "They have a different version."; break; } } else if (lobby.started == "true") { str += "This game is in progress."; } else if (lobby.numSlots != "" && lobby.lobby.users.Count >= Convert.ToInt32(lobby.numSlots)) { str += "Lobby is full."; } else if (lobby.type != "2") { str += "This game is not public."; } else if (lobby.hasLocalMods) { str += "This game is using non-workshop mods."; } text2 = str + ")"; DuckGame.Graphics.DrawRect(new Vec2(x1, y), new Vec2((float)((double)x1 + (double)this._box.width - 14.0), y + 36f), Color.Black * 0.5f, new Depth(0.99f)); } this._fancyFont.maxWidth = 1000; this._fancyFont.Draw(text2, new Vec2((float)((double)x1 + 36.0 + 10.0), y + 2f), Color.Yellow, new Depth(0.5f)); if (lobby.version == DG.version) { this._fancyFont.Draw(lobby.version, new Vec2((float)((double)x1 + 430.0 + 10.0), y + 2f), Colors.DGGreen * 0.35f, new Depth(0.5f)); } else { this._fancyFont.Draw(lobby.version, new Vec2((float)((double)x1 + 430.0 + 10.0), y + 2f), Colors.DGRed * 0.35f, new Depth(0.5f)); } DuckGame.Graphics.Draw(this._steamIcon, x1 + 36f, y + 2.5f, new Depth(0.5f)); this._fancyFont.Draw(text1, new Vec2(x1 + 36f, y + 6f + (float)this._fancyFont.characterHeight), Color.LightGray, new Depth(0.5f)); } } else { break; } } if (Mouse.available && !this._gamepadMode) { this._cursor.depth = new Depth(1f); this._cursor.scale = new Vec2(1f, 1f); this._cursor.position = Mouse.position; this._cursor.frame = 0; if (Editor.hoverTextBox) { this._cursor.frame = 5; this._cursor.position.y -= 4f; this._cursor.scale = new Vec2(0.5f, 1f); } this._cursor.Draw(); } } base.Draw(); }