public void Stop() { //if (Core.net.isOnline) { networkThreaad.Stop(); ClientPacketSender.Disconnect(core.GetPlayerName()); core.currentGui = new GuiMainMenu(); core.SetWorld(null); SetOnline(false); if (core.GetPlayerName().Equals("Player")) { //Thread t = new Thread(StopLocalServer); // t.Start(); StopLocalServer(); } } //else if (core.world != null) //{ // core.currentgui = new guimainmenu(); // core.world = null; // core.console.adddebugstring("closing server..."); // //thread t = new thread(() => servercore.instance.stop()); // //t.start(); // servercore.instance.stop(); // core.console.adddebugstring("server closed"); // core.net.isonline = false; //} core.cam.control = false; }
public override bool LeftClick() { if (buttons[0].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { ClientPacketSender.SendConfrimSelect(ConfrimType.SelectFaction, 1); core.currentGui = null; return(true); } else if (buttons[1].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { ClientPacketSender.SendConfrimSelect(ConfrimType.SelectFaction, 3); core.currentGui = null; return(true); } else if (buttons[2].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { ClientPacketSender.SendConfrimSelect(ConfrimType.SelectFaction, 2); core.currentGui = null; return(true); } else { return(false); } }
private void StartLocalServer() { ServerCore sc = new ServerCore(false); Thread.Sleep(300); Thread t = new Thread(() => ClientPacketSender.Login("Player", "PassClient")); t.Start(); }
private static void GetServers() { if (Client.instance?.ServerManagerTCP == null) { Client.instance.ConnectToServerManager(); } ClientPacketSender.RequestServerList(); }
IEnumerator AutoTimeSync() { Timer.Start(); while (isConnected) { ClientPacketSender.TimeSync(Timer.ElapsedMilliseconds); yield return(new WaitForSeconds(1)); } Timer.Stop(); }
public void CreateGame() { if (!_creatingGame) { _creatingGame = true; Client.instance.ConnectToServerManager(); GameserverInstance testInstance = new GameserverInstance() { ServerName = Client.instance.Username + "-server" }; ClientPacketSender.CreateServerRequest(testInstance); } }
private void FixedUpdate() { if (!Client.instance.isConnected) { return; } ClientPacketSender.PlayerMovement( Head.transform.position, Head.transform.rotation, GetHandData(LeftHand, _leftHandSpellController), GetHandData(RightHand, _rightHandSpellController) ); }
public static void WelcomeMessage(Packet packet) { string msg = packet.ReadString(); int id = packet.ReadInt(); Debug.Log($"Welcome message from server: {msg}"); Client.instance.ID = id; //Send a response to server here ClientPacketSender.WelcomeReceived(); //Setup udp client on same port as TCP client Client.instance.udp.Connect(Client.instance.ip, Client.instance.port, ((IPEndPoint)Client.instance.tcp.client.Client.LocalEndPoint).Port); OnClientConnectedToServer?.Invoke(); }
public override bool LeftClick() { if (buttons[0].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { ClientPacketSender.SendRespawn(); core.currentGuiAdd = null; core.cam.control = false; return(true); } else if (buttons[1].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { ClientNetwork net = ClientNetwork.GetClientNetwork(); net.Stop(); core.currentGuiAdd = null; return(true); } return(false); }
public override bool LeftClick() { ClientNetwork net = ClientNetwork.GetClientNetwork(); foreach (InputBox b in tBox) { b.isSelected = false; } if (isWar) { if (buttons[0].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { if (tBox[0].stringInBox != null && tBox[1].stringInBox != null && tBox[0].stringInBox.Length > 0 && tBox[1].stringInBox.Length > 0) { if (!net.IsLogging()) { core.SetWorld(new World(true)); ClientNetwork.GetClientNetwork().Start(); Core.console.AddDebugString("Connecting..."); Thread t = new Thread(() => ClientPacketSender.Login(tBox[0].stringInBox, tBox[1].stringInBox)); t.Start(); Settings.SaveLoginInfo(tBox[0].stringInBox, tBox[1].stringInBox); return(true); } else { return(true); } } } else if (buttons[1].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { if (tBox[0].stringInBox != null && tBox[1].stringInBox != null && tBox[0].stringInBox.Length > 0 && tBox[1].stringInBox.Length > 0) { if (!net.IsLogging()) { ClientNetwork.GetClientNetwork().Start(); Core.console.AddDebugString("Registering..."); Thread t = new Thread(() => ClientPacketSender.Register(tBox[0].stringInBox, tBox[1].stringInBox)); t.Start(); Settings.SaveLoginInfo(tBox[0].stringInBox, tBox[1].stringInBox); return(true); } else { return(true); } } } else if (buttons[2].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { core.currentGui = new GuiMainMenu(); Settings.SaveLoginInfo(tBox[0].stringInBox, tBox[1].stringInBox); return(true); } else { foreach (InputBox b in tBox) { if (b.Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { b.isSelected = true; return(true); } } } return(false); } else { if (buttons[0].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { if (tBox[0].stringInBox != null && tBox[1].stringInBox != null && tBox[2].stringInBox != null && tBox[0].stringInBox.Length > 0 && tBox[1].stringInBox.Length > 0 && tBox[2].stringInBox.Length > 0) { if (!net.IsLogging()) { Core.console.AddDebugString("Connecting..."); core.SetWorld(new World(true)); core.currentGui = null; ClientNetwork.GetClientNetwork().Start(); Thread t = new Thread(() => ClientPacketSender.Connect(tBox[0].stringInBox, tBox[1].stringInBox, int.Parse(tBox[2].stringInBox))); t.Start(); Settings.SaveLoginInfo(tBox[0].stringInBox, tBox[1].stringInBox, tBox[2].stringInBox); return(true); } else { return(true); } } } else if (buttons[1].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { core.currentGui = new GuiMainMenu(); Settings.SaveLoginInfo(tBox[0].stringInBox, tBox[1].stringInBox, tBox[2].stringInBox); return(true); } else { foreach (InputBox b in tBox) { if (b.Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y))) { b.isSelected = true; return(true); } } } return(false); } }
private void LeftClick() { bool isMouseClick = false; bool check = false; for (int i = 0; i < world.selectedShips.Count; i++) { if (world.selectedShips[i].isLive && world.selectedShips[i].isSelected && guiInGame.controlButton.Rect.Contains(new Point((int)inputManager.cursor.Position.X, (int)inputManager.cursor.Position.Y))) { if (!world.selectedShips[i].isControled) { world.selectedShips[i].isControled = true; world.selectedShips[i].runnigOutVector = Vector2.Zero; check = true; cam.control = true; isMouseClick = true; ClientPacketSender.SendSelectShip(true); } else { cam.control = false; check = true; world.selectedShips[i].isControled = false; world.selectedShips[i].moveToVector = Vector2.Zero; isMouseClick = true; ClientPacketSender.SendSelectShip(false); } Sounds.Play(Sounds.buttonClick, Settings.soundVolume / 2f, random.Next(-2, 2) / 100f); break; } } if (!isMouseClick) { check = false; for (int i = 0; i < guiInGame.selShips.Count; i++) { if (guiInGame.selSlots[i].Rect.Contains((int)inputManager.cursor.Position.X, (int)inputManager.cursor.Position.Y) && world.selectedShips[i + 8 * (guiInGame.pageNum - 1)].isLive) { for (int j = 0; j < world.selectedShips.Count; j++) { world.selectedShips[j].isSelected = false; } world.selectedShips[i + 8 * (guiInGame.pageNum - 1)].isSelected = true; check = true; isMouseClick = true; } } if (guiInGame.leftSelShips.Rect.Contains((int)inputManager.cursor.Position.X, (int)inputManager.cursor.Position.Y)) { if (guiInGame.pageNum - 1 > 0) { guiInGame.pageNum--; } check = true; isMouseClick = true; Sounds.Play(Sounds.buttonClick, Settings.soundVolume / 2f, random.Next(-2, 2) / 100f); } else if (guiInGame.rightSelShips.Rect.Contains((int)inputManager.cursor.Position.X, (int)inputManager.cursor.Position.Y)) { if ((guiInGame.pageNum + 1) * 8 <= (world.selectedShips.Count + 8)) { guiInGame.pageNum++; } check = true; isMouseClick = true; Sounds.Play(Sounds.buttonClick, Settings.soundVolume / 2f, random.Next(-2, 2) / 100f); } if (!check && !cam.control) { for (int i = 0; i < world.selectedShips.Count; i++) { world.selectedShips[i].isSelected = false; } world.selectedShips.Clear(); } } bool selectedFromRectangle = false; bool selectedFromClick = false; guiInGame.selectRect = new Rectangle(); Vector2 pressedPos = Vector2.Transform(new Vector2(inputManager.mousePressedVector.X - cam.screenCenter.X + screenWidth / 2, inputManager.mousePressedVector.Y - cam.screenCenter.Y + screenHeight / 2), Matrix.Invert(cam.defaultScreen)); if (!isMouseClick && !isChat) { if (pressedPos.X - inputManager.cursorAdvancedPosition.X >= 5) { if (pressedPos.Y - inputManager.cursorAdvancedPosition.Y >= 5) { guiInGame.selectRect = new Rectangle((int)inputManager.cursorAdvancedPosition.X, (int)inputManager.cursorAdvancedPosition.Y, (int)(pressedPos.X - inputManager.cursorAdvancedPosition.X), (int)(pressedPos.Y - inputManager.cursorAdvancedPosition.Y)); selectedFromRectangle = true; } else if (inputManager.cursorAdvancedPosition.Y - pressedPos.Y >= 5) { guiInGame.selectRect = new Rectangle((int)inputManager.cursorAdvancedPosition.X, (int)pressedPos.Y, (int)(pressedPos.X - inputManager.cursorAdvancedPosition.X), (int)(inputManager.cursorAdvancedPosition.Y - pressedPos.Y)); selectedFromRectangle = true; } } else if (inputManager.cursorAdvancedPosition.X - pressedPos.X >= 5) { if (pressedPos.Y - inputManager.cursorAdvancedPosition.Y >= 5) { guiInGame.selectRect = new Rectangle((int)pressedPos.X, (int)inputManager.cursorAdvancedPosition.Y, (int)(inputManager.cursorAdvancedPosition.X - pressedPos.X), (int)(pressedPos.Y - inputManager.cursorAdvancedPosition.Y)); selectedFromRectangle = true; } else if (inputManager.cursorAdvancedPosition.Y - pressedPos.Y >= 5) { guiInGame.selectRect = new Rectangle((int)pressedPos.X, (int)pressedPos.Y, (int)(inputManager.cursorAdvancedPosition.X - pressedPos.X), (int)(inputManager.cursorAdvancedPosition.Y - pressedPos.Y)); selectedFromRectangle = true; } } else if (!selectedFromRectangle && !cam.control) { for (int i = 0; i < world.ships.Count; i++) { Rectangle rect = new Rectangle((int)world.ships[i].Position.X - world.ships[i].Text.Width / 2, (int)world.ships[i].Position.Y - world.ships[i].Text.Height / 2, world.ships[i].Text.Width, world.ships[i].Text.Height); if (rect.Contains((int)inputManager.cursorAdvancedPosition.X, (int)inputManager.cursorAdvancedPosition.Y) && world.ships[i].shipName.Equals(playerName)) { for (int j = 0; j < world.selectedShips.Count; j++) { world.selectedShips[j].isSelected = false; } world.selectedShips.Clear(); selectedFromClick = true; world.ships[i].isSelected = true; world.selectedShips.Add(world.ships[i]); break; } } /*if (!selectedFromClick) * for (int i = 0; i < motherShips.Count; i++) * { * Rectangle rect = new Rectangle((int)motherShips[i].Position.X - motherShips[i].Text.Width / 2, (int)motherShips[i].Position.Y - motherShips[i].Text.Height / 2, motherShips[i].Text.Width, motherShips[i].Text.Height); * if (rect.Contains((int)InputManager.cursorAdvancedPosition.X, (int)InputManager.cursorAdvancedPosition.Y) && motherShips[i].shipFaction == Faction.Human) * { * for (int j = 0; j < world.selectedShips.Count; j++) * { * world.selectedShips[j].isSelected = false; * } * world.selectedShips.Clear(); * selectedFromClick = true; * motherShips[i].isSelected = true; * world.selectedShips.Add(motherShips[i]); * break; * } * }*/ /*if (!selectedFromClick) * for (int i = 0; i < stations.Count; i++) * { * Rectangle rect = new Rectangle((int)stations[i].Position.X - stations[i].Text.Width / 2, (int)stations[i].Position.Y - stations[i].Text.Height / 2, stations[i].Text.Width, stations[i].Text.Height); * if (rect.Contains((int)InputManager.cursorAdvancedPosition.X, (int)InputManager.cursorAdvancedPosition.Y)) //&& stations[i].shipFaction == Faction.Human) * { * for (int j = 0; j < world.selectedShips.Count; j++) * { * world.selectedShips[j].isSelected = false; * } * world.selectedShips.Clear(); * selectedFromClick = true; * stations[i].isSelected = true; * world.selectedShips.Add(stations[i]); * break; * } * }*/ } } if (selectedFromRectangle && !cam.control) { for (int i = 0; i < world.selectedShips.Count; i++) { world.selectedShips[i].isSelected = false; } world.selectedShips.Clear(); for (int i = 0; i < world.ships.Count; i++) { if (guiInGame.selectRect.Contains((int)world.ships[i].Position.X, (int)world.ships[i].Position.Y) && world.ships[i].shipName.Equals(playerName)) { world.selectedShips.Add(world.ships[i]); } } /*for (int i = 0; i < motherShips.Count; i++) * { * if (selectRect.Contains((int)motherShips[i].Position.X, (int)motherShips[i].Position.Y) && motherShips[i].shipFaction == Faction.Human) * { * world.selectedShips.Add(motherShips[i]); * } * }*/ /*for (int i = 0; i < stations.Count; i++) * { * if (selectRect.Contains((int)stations[i].Position.X, (int)stations[i].Position.Y))// && stations[i].shipFaction == Faction.Human) * { * world.selectedShips.Add(stations[i]); * } * }*/ if (world.selectedShips.Count == 1) { world.selectedShips[0].isSelected = true; } } }
public void ReadyUp(bool ready) { Ready = ready; ClientPacketSender.ReadyStatusUpdate(ready); }