/// <summary> /// Adds new slot to the UI /// </summary> /// <param name="server"></param> public void AddLANServerSlot(LanEntry server) { if (serverList != null) { ServerSlot item = Instantiate(serverItem); item.SetupLAN(server); item.transform.SetParent(serverList.transform); } }
private void CreateServerSlot(Region region) { // Create Obj GameObject serverSlotObj = Instantiate(_serverSlotPrefab, Vector3.zero, Quaternion.identity) as GameObject; serverSlotObj.transform.SetParent(_serverSlotGrid, false); // Set values ServerSlot serverSlot = serverSlotObj.GetComponent <ServerSlot>(); serverSlot.ServerName = region.Code.ToString(); serverSlot.RegionCode = (uint)region.Code; serverSlot.Ping = region.Ping; // Cache _serverSlots.Add(serverSlot); }
public void OnMatchCreate(bool success, string extendedInfo, List <MatchInfoSnapshot> matchList) { if (!success || matchList == null) { return; } foreach (MatchInfoSnapshot match in matchList) { ServerSlot roomListItem = Instantiate(serverItem); roomListItem.transform.SetParent(serverList.transform); roomList.Add(roomListItem); if (roomListItem != null) { roomListItem.SetupWAN(match, JoinRoom); } } }
/// <summary> /// Handles "ready" button action /// </summary> public void ReadyGame() { networkDiscovery = FindObjectOfType <OxyniteNetworkDiscovery>(); if (roomList.Count > 0) { ServerSlot serverSlot = roomList[Random.Range(0, roomList.Count)]; JoinRoom(serverSlot.GetMatch()); } else if (networkDiscovery.GetLanEntries() != null) { List <LanEntry> entries = networkDiscovery.GetLanEntries(); LanEntry server = entries[Random.Range(0, entries.Count)]; networkManager.StartGame(server.ipAddress); } else { HostGame(); } }
public static void OnPlayerLeft(Player player, ServerSlot slot, bool announced) { player.active = false; if (announced) { ProgramLog.Log("{0} @ {1}: LEAVE {2}", slot.remoteAddress, slot.Id, player.name); var msg = NewNetMessage.PrepareThreadInstance(); msg.SynchBegin(player.whoAmI, 0 /*inactive*/); if (player.DisconnectReason != null) { msg.PlayerChat(255, string.Concat(player.Name, " disconnected (", player.DisconnectReason, ")."), 255, 165, 0); } else { msg.PlayerChat(255, string.Concat(player.name, " has left."), 255, 240, 20); } msg.BroadcastExcept(player.whoAmI); } var ctx = new HookContext { Player = player, Sender = player, }; var args = new HookArgs.PlayerLeftGame { Slot = slot.Id }; HookPoints.PlayerLeftGame.Invoke(ref ctx, ref args); }
public override void Process(int whoAmI, byte[] readBuffer, int length, int num) { int num13 = ReadInt32(readBuffer); int num14 = ReadInt32(readBuffer); bool flag3 = true; if (num13 == -1 || num14 == -1) { flag3 = false; } else { if (num13 < 10 || num13 > Main.maxTilesX - 10) { flag3 = false; } else { if (num14 < 10 || num14 > Main.maxTilesY - 10) { flag3 = false; } } } int num15 = Netplay.GetSectionX(Main.spawnTileX) - 2; int num16 = Netplay.GetSectionY(Main.spawnTileY) - 1; int num17 = num15 + 5; int num18 = num16 + 3; if (num15 < 0) { num15 = 0; } if (num17 >= Main.maxSectionsX) { num17 = Main.maxSectionsX - 1; } if (num16 < 0) { num16 = 0; } if (num18 >= Main.maxSectionsY) { num18 = Main.maxSectionsY - 1; } int num19 = (num17 - num15) * (num18 - num16); int num20 = -1; int num21 = -1; if (flag3) { num13 = Netplay.GetSectionX(num13) - 2; num14 = Netplay.GetSectionY(num14) - 1; num20 = num13 + 5; num21 = num14 + 3; if (num13 < 0) { num13 = 0; } if (num20 >= Main.maxSectionsX) { num20 = Main.maxSectionsX - 1; } if (num14 < 0) { num14 = 0; } if (num21 >= Main.maxSectionsY) { num21 = Main.maxSectionsY - 1; } for (int num22 = num13; num22 < num20; num22++) { for (int num23 = num14; num23 < num21; num23++) { if (num22 < num15 || num22 >= num17 || num23 < num16 || num23 >= num18) { num19++; } } } } ServerSlot serverSock = Terraria.Netplay.Clients[whoAmI] as ServerSlot; if (serverSock.state == SlotState.SENDING_WORLD) { serverSock.state = SlotState.SENDING_TILES; } else { serverSock.Kick("Invalid operation at this state."); } NewNetMessage.SendData(9, whoAmI, -1, Lang.inter[44], num19, 0f, 0f, 0f, 0); Terraria.Netplay.Clients[whoAmI].StatusText2 = "is receiving tile data"; Terraria.Netplay.Clients[whoAmI].StatusMax += num19; for (int num24 = num15; num24 < num17; num24++) { for (int num25 = num16; num25 < num18; num25++) { NewNetMessage.SendSection(whoAmI, num24, num25, false); } } if (flag3) { for (int num26 = num13; num26 < num20; num26++) { for (int num27 = num14; num27 < num21; num27++) { NewNetMessage.SendSection(whoAmI, num26, num27, true); } } NewNetMessage.SendData(11, whoAmI, -1, String.Empty, num13, (float)num14, (float)(num20 - 1), (float)(num21 - 1), 0); } NewNetMessage.SendData(11, whoAmI, -1, String.Empty, num15, (float)num16, (float)(num17 - 1), (float)(num18 - 1), 0); for (int num28 = 0; num28 < 400; num28++) { if (Main.item[num28].active) { NewNetMessage.SendData(21, whoAmI, -1, String.Empty, num28, 0f, 0f, 0f, 0); NewNetMessage.SendData(22, whoAmI, -1, String.Empty, num28, 0f, 0f, 0f, 0); } } for (int num29 = 0; num29 < 200; num29++) { if (Main.npc[num29].active) { System.Diagnostics.Debug.WriteLine("Sending 23"); NewNetMessage.SendData(23, whoAmI, -1, String.Empty, num29, 0f, 0f, 0f, 0); } } for (int num30 = 0; num30 < 1000; num30++) { if (Main.projectile[num30].active && (Main.projPet[Main.projectile[num30].type] || Main.projectile[num30].netImportant)) { NewNetMessage.SendData(27, whoAmI, -1, String.Empty, num30, 0f, 0f, 0f, 0); } } NewNetMessage.SendData(49, whoAmI, -1, String.Empty, 0, 0f, 0f, 0f, 0); NewNetMessage.SendData(57, whoAmI, -1, String.Empty, 0, 0f, 0f, 0f, 0); NewNetMessage.SendData(7, whoAmI, -1, String.Empty, 0, 0f, 0f, 0f, 0); }
public override void Process(int whoAmI, byte[] readBuffer, int length, int num) { int num8 = BitConverter.ToInt32(readBuffer, num); num += 4; int num9 = BitConverter.ToInt32(readBuffer, num); num += 4; bool flag3 = !(num8 == -1 || num8 <10 || num8> Main.maxTilesX - 10 || num9 == -1 || num9 <10 || num9> Main.maxTilesY - 10); int num10 = 1350; if (flag3) { num10 *= 2; } ServerSlot serverSock = NetPlay.slots[whoAmI]; if (serverSock.state == SlotState.SENDING_WORLD) { serverSock.state = SlotState.SENDING_TILES; } else { serverSock.Kick("Invalid operation at this state."); } NetMessage.SendData(9, whoAmI, -1, "Receiving tile data", num10); serverSock.statusText2 = "is receiving tile data"; serverSock.statusMax += num10; int sectionX = NetPlay.GetSectionX(Main.spawnTileX); int sectionY = NetPlay.GetSectionY(Main.spawnTileY); for (int x = sectionX - 1; x < sectionX + 2; x++) { for (int y = sectionY - 1; y < sectionY + 2; y++) { NetMessage.SendSection(whoAmI, x, y); } } if (flag3) { num8 = NetPlay.GetSectionX(num8); num9 = NetPlay.GetSectionY(num9); for (int num11 = num8 - 1; num11 < num8 + 2; num11++) { for (int num12 = num9 - 1; num12 < num9 + 2; num12++) { NetMessage.SendSection(whoAmI, num11, num12); } } NetMessage.SendData(11, whoAmI, -1, "", num8 - 1, (float)(num9 - 1), (float)(num8 + 1), (float)(num9 + 1)); } NetMessage.SendData(11, whoAmI, -1, "", sectionX - 1, (float)(sectionY - 1), (float)(sectionX + 1), (float)(sectionY + 1)); //Can't switch to a for each because there are 201 items. for (int itemIndex = 0; itemIndex < 200; itemIndex++) { if (Main.item[itemIndex].Active) { NetMessage.SendData(21, whoAmI, -1, "", itemIndex); NetMessage.SendData(22, whoAmI, -1, "", itemIndex); } } //Can't switch to a for each because there are 1001 NPCs. for (int npcIndex = 0; npcIndex < NPC.MAX_NPCS; npcIndex++) { if (Main.npcs[npcIndex].Active) { NetMessage.SendData(23, whoAmI, -1, "", npcIndex); } } NetMessage.SendData(49, whoAmI); NetMessage.SendData(57, whoAmI); //Send NPC Names... foreach (var npcId in new int[] { 17, 18, 19, 20, 22, 38, 54, 107, 108, 124 }) { NetMessage.SendData(56, whoAmI, -1, String.Empty, npcId); } }