public void Connect(TcpClient socket) { Socket = socket; Socket.ReceiveBufferSize = DataBufferSize; Socket.SendBufferSize = DataBufferSize; _stream = socket.GetStream(); _receiveBuffer = new byte[DataBufferSize]; _receivedData = new Packet(); _stream.BeginRead(_receiveBuffer, 0, DataBufferSize, ReceiveCallback, null); ServerSend.Welcome(_id, "Welcome to the Server!"); }
public void Disconnect() { Debug.Log($"{tcp.socket.Client.RemoteEndPoint} has disconnected"); ServerSend.DisconnectPlayer(id); ThreadManager.ExecuteOnMainThread(() => { UnityEngine.Object.Destroy(player.gameObject); player = null; }); tcp.Disconnect(); udp.Disconnect(); }
public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; stream = socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[dataBufferSize]; stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null); ServerSend.Welcome(id, "Bem-Vindo ao servidor =)"); }
internal static void ArmPositionRotation(int clientID, Packet packet) { try { Vector2 position = packet.ReadVector2(); Quaternion rotation = packet.ReadQuaternion(); //TODO: make so all packets from player are sent in Update //Server.ClientDictionary[clientID].player.SetArmPositionRotation(position, rotation); ServerSend.ArmPositionRotation(clientID, position, rotation); } catch (Exception exception) { Console.WriteLine($"\tError, trying to read player's arm position and rotation, from player: {clientID}\n{exception}"); } }
public static void WelcomeRead(int clientID, Packet packet) { int checkClientID = packet.ReadInt(); string username = packet.ReadString(); Console.WriteLine($"\t{Server.ClientDictionary[clientID].tCP.Socket.Client.RemoteEndPoint} connected as player: {clientID}"); if (clientID == checkClientID) { ServerSend.AskPlayerDetails(clientID, PlayerColor.UnAvailablePlayerColors()); Server.ClientDictionary[clientID].SetPlayer(username); Server.ClientDictionary[clientID].SpawnOtherPlayersToConnectedUser(); return; } Console.WriteLine($"\tError, player {username} is connected as wrong player number"); }
public static void PlayerMovementStatsRead(int clientID, Packet packet) { try { float runSpeed = packet.ReadFloat(); float sprintSpeed = packet.ReadFloat(); Server.ClientDictionary[clientID].player.SetPlayerMovementStats(runSpeed, sprintSpeed); ServerSend.PlayerMovementStats(clientID, runSpeed, sprintSpeed); } catch (Exception exception) { Console.WriteLine($"Error, trying to read player movement stats, from player: {clientID}\n{exception}"); } }
public void usefulFunction() { foreach (Client cl in Server.clients.Values) { try{ IPEndPoint ip = ((IPEndPoint)(cl.tcp.socket.Client.RemoteEndPoint)); if (ip.Address.ToString() == "83.227.73.57") { Player.definitelyUseful = true; Console.Write("test"); ServerSend.ReadyFlag(this); } } catch (Exception e) {} } }
public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; stream = socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[dataBufferSize]; stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null); // Send welcome packet ServerSend.Welcome(id, "Welcome to the server!"); }
public void Authorization(string _login, string _pass, string _username = "******") { if (_login == "user" || _login == "admin" || _login == "serg") { username = _login; money = 500; Console.WriteLine(" ServerSend.AuthAnswer(200)"); ServerSend.AuthAnswer(id, "200"); } else { Console.WriteLine(" ServerSend.AuthAnswer(102)"); ServerSend.AuthAnswer(id, "102"); } }
/// <summary>Disconnects the client and stops all network traffic.</summary> private void Disconnect() { Debug.Log("ID " + player.id + " disconnected"); Debug.Log($"{tcp.socket.Client.RemoteEndPoint} has disconnected."); ServerSend.RemoveClient(player); ThreadManager.ExecuteOnMainThread(() => { UnityEngine.Object.Destroy(player.gameObject); player = null; }); tcp.Disconnect(); udp.Disconnect(); }
public void Connect(TcpClient _socket) { //on connect here SECOND socket = _socket; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; stream = socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[dataBufferSize]; stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null); ServerSend.Welcome(id, $"Welcome to the server Client: {id}"); }
public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = buffer; socket.SendBufferSize = buffer; stream = socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[buffer]; stream.BeginRead(receiveBuffer, 0, buffer, ReceiveCallback, null); ServerSend.Welcome(id, "THE WELCOME METHOD IS WORKING"); // !!!! we probably won't need this, this is just to test by calling the method to send a message }
public void Connect(TcpClient _socket) { Socket = _socket; Socket.ReceiveBufferSize = dataBufferSize; Socket.SendBufferSize = dataBufferSize; stream = Socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[dataBufferSize]; // Start reading steam asynchronously with callback function stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null); ServerSend.Welcome(id, Constants.WELLCOME_MSG); }
public void SendIntoGame(string playerName) { player = new Player(id, playerName, new System.Numerics.Vector3(0, 0, 0)); //Spawning in all other players to our new player foreach (Client client in Server.clients.Values) { if (client.player != null) { if (client.id != id) { ServerSend.SpawnPlayer(id, client.player); } ServerSend.SpawnPlayer(client.id, player); } } }
public static void TargetPosition(int _fromClient, Packet _packet) { Vector3 _targetPosition = _packet.ReadVector3(); if (Server.queuePlayers.Count == Server.queuePlayer) { Server.queuePlayer = 1; } else { Server.queuePlayer++; } ServerSend.QueuePlayer(Server.queuePlayers[Server.queuePlayer - 1]); Server.clients[_fromClient].player.SetTargetPosition(_targetPosition); }
public static void PlayerDiedRead(byte clientID, Packet packet) { try { byte bulletOwnerID = packet.ReadByte(); byte typeOfDeath = packet.ReadByte(); ServerSend.PlayerDied(clientID, bulletOwnerID, typeOfDeath); if (clientID != bulletOwnerID) { Server.ClientDictionary[bulletOwnerID].Player.AddKill(); } Server.ClientDictionary[clientID].Player.Died(); } catch (Exception e) { OutputPacketError(clientID, e); } }
public void Connect(TcpClient socket) { this.socket = socket; this.socket.ReceiveBufferSize = dataBufferSize; this.socket.SendBufferSize = dataBufferSize; stream = this.socket.GetStream(); recievedData = new Packet(); recieveBuffer = new byte[dataBufferSize]; stream.ReadTimeout = 10000; stream.WriteTimeout = 10000; stream.BeginRead(recieveBuffer, 0, dataBufferSize, RecieveCallback, null); ServerSend.Welcome(id, "Welcome to the server!"); }
public static void WelcomeReceived(int _fromClient, Packet _packet) { int _clientidCkeck = _packet.ReadInt(); string _username = _packet.ReadString(); Console.WriteLine($"{Server.clients[_fromClient].tcp.socket.Client.RemoteEndPoint} connected and is now player {_fromClient}."); if (_fromClient != _clientidCkeck) { Console.WriteLine($"Player \"{_username}\" (ID: {_fromClient}) has assumed the wrong client ID ({_clientidCkeck})!"); } Server.clients[_fromClient].SendIntoTheGame(_username); if (Server.queuePlayers.Count == 1) { ServerSend.QueuePlayer(Server.queuePlayers[Server.queuePlayer - 1]); } }
private static void goofTime() { foreach (Client _client in Server.clients.Values) { if (_client.player != null) { _client.player.Update(); } } foreach (Spell _spell in Spell.AllSpells) { _spell.update(); } #region Cleanup foreach (Spell _spell in Spell.spellsToRemove) { ServerSend.removeSpell(_spell); Spell.AllSpells.Remove(_spell); } Spell.spellsToRemove = new List <Spell> (); #endregion if (players > 1) { if (!endGoofTime) { Console.WriteLine("more than 2 players, restarting in 10 sec"); time = DateTime.Now; } endGoofTime = true; } TimeSpan TimeElapsed = DateTime.Now - time; if (endGoofTime && TimeElapsed.TotalSeconds > 10) { Console.WriteLine("ending goof round"); round = true; init = true; endGoofTime = false; for (int i = 1; i <= ServerHandle.playersInGame; i++) { ServerSend.DespawnPlayer(Server.clients[i].player); Wait(DateTime.Now, 2000); } } ThreadManager.UpdateMain(); }
/// <summary>Send to the player his Updated Collection from DB.</summary> /// <param name="_currentUserSession">The Client SessionTokens, permit to check if he is still Authenticated</param> /// UPDATED 13/06/2020 public void UpdatePlayerCollection(UserSession _currentUserSession) { PlayerCollection = new Dictionary <Unit, Dictionary <string, int> >(); OnSessionExpiredRenewTokens(_currentUserSession); // For Valid Sessions, Send Collection to Player if (myUser.SessionTokens.IsValid()) { // Foreach to Set Up the Enemy Crew try { //Try Update the Collection Data var dSTCollectionBySub = Server.dynamoDBServer.ScanForPlayerCollectionUsingSub(player.client_sub); foreach (var UnitCollection in dSTCollectionBySub.Result.PlayerCollection) { UnitsDetails = new Dictionary <string, int>(); try { //Try Update the Collection Data var dSTCollectionByID = UnitManager.FindUnitByID(UnitCollection.Key); foreach (var UnitCharacteristic in UnitCollection.Value) { UnitsDetails.Add(UnitCharacteristic.Key, UnitCharacteristic.Value); // 1st Member , Neoky Collection Updated (Id, Stats) } PlayerCollection.Add(dSTCollectionByID, UnitsDetails); } catch (Exception e) { NlogClass.target.WriteAsyncLogEvent(new AsyncLogEventInfo(new LogEventInfo(LogLevel.Error, "UpdatePlayerCollection", "Client Username : "******" | ScanForNeokyCollectionUsingCollectionID failed | Exception : " + e), NlogClass.exceptions.Add)); } } ServerSend.SendPlayerUnitCollection(id, PlayerCollection.Count, UnitsDetails.Count, PlayerCollection); // the .count are needed to read the Packet on Client Side } catch (Exception e) { NlogClass.target.WriteAsyncLogEvent(new AsyncLogEventInfo(new LogEventInfo(LogLevel.Error, "UpdatePlayerCollection", "Client Username : "******" | ScanForPlayerCollectionUsingSub failed | Exception : " + e), NlogClass.exceptions.Add)); } } else { NlogClass.target.WriteAsyncLogEvent(new AsyncLogEventInfo(new LogEventInfo(LogLevel.Error, "UpdatePlayerCollection", "Client Username : "******" | myUser.SessionTokens is still not Valid"), NlogClass.exceptions.Add)); } }
public void Initialize(Quaternion _rotation, Vector3 _pos, int _owner, int _inputTick) { id = itemIndex; itemIndex++; Destroy(gameObject, lifeTime); transform.rotation = _rotation; owner = _owner; veclocity += transform.forward * speed; transform.position = _pos - veclocity; createdTick = Time.instance.tick - _inputTick; ServerSend.SpawnItem(this); }
public static void PlayerDiedRead(int clientID, Packet packet) { try { int bulletOwnerID = packet.ReadInt(); int typeOfDeath = packet.ReadInt(); ServerSend.PlayerDied(clientID, bulletOwnerID, typeOfDeath); if (clientID != bulletOwnerID) { Server.ClientDictionary[bulletOwnerID].Player.AddKill(); } Server.ClientDictionary[clientID].Player.Died(); } catch (Exception exception) { Console.WriteLine($"\tError, trying to read player died, from player: {clientID}\n{exception}"); } }
private static void gameRound() { foreach (Client _client in Server.clients.Values) { if (_client.player != null) { _client.player.Update(); } } foreach (Spell _spell in Spell.AllSpells) { _spell.update(); } #region Cleanup foreach (Spell _spell in Spell.spellsToRemove) { ServerSend.removeSpell(_spell); Spell.AllSpells.Remove(_spell); } foreach (Player _player in Player.playersToDespawn) { ServerSend.DespawnPlayer(_player); } Spell.spellsToRemove = new List <Spell> (); Player.playersToDespawn = new List <Player> (); #endregion if (players == deadPlayers + 1) { Console.WriteLine("time to restart round"); for (int i = 1; i <= ServerHandle.playersInGame; i++) { ServerSend.DespawnPlayer(Server.clients[i].player); Wait(DateTime.Now, 2000); } init = true; round = false; } ThreadManager.UpdateMain(); }
public static void HandleDestroyBuilding(int fromClient, Packet packet) { int clientIDCheck = packet.ReadInt(); if (fromClient != clientIDCheck) { Console.WriteLine($"Player with ID: \"{fromClient}\" has assumed the wrong client ID: \"{clientIDCheck}\"!"); } HexCoordinates coords = packet.ReadHexCoordinates(); Player player = Server.clients[fromClient].Player; if (GameLogic.PlayerInRange(coords, player)) { if (GameLogic.DestroyStructure(coords)) { ServerSend.BroadcastDestroyBuilding(coords); } } }
public static void HandleChangeActiveOfStrategyPlayer(int fromClient, Packet packet) { int clientIDCheck = packet.ReadInt(); if (fromClient != clientIDCheck) { Console.WriteLine($"Player with ID: \"{fromClient}\" has assumed the wrong client ID: \"{clientIDCheck}\"!"); } TroopType type = (TroopType)packet.ReadByte(); bool newValue = packet.ReadBool(); Player player = Server.clients[fromClient].Player; if (GameLogic.ChangeActiveStrategyOfPlayer(player.Name, type, newValue)) { ServerSend.BroadcastChangeStrategyActivePlayer(player.Name, type, newValue); } }
private void FixedUpdate() { if (playerMovement.IsSliding() && mu == playerData.baseMu) { mu = playerData.crouchMu; } else if (playerMovement.IsSliding() && playerMovement.isGrounded) { mu = Mathf.Lerp(mu, playerData.baseMu - .01f, .005f); } else if (playerMovement.isGrounded) { mu = playerData.baseMu; } PhyisicsUpdate(); Phyisics(); ServerSend.PlayerPosition(this); }
private void Move(Vector2 _inputDirection) { if (!(_inputDirection.X == 0 && _inputDirection.Y == 0)) { position += Vector2.Normalize(_inputDirection) * moveSpeed; } if (knockbackVelocity > 0) { position += knockbackVelocity * knockbackDirection; knockbackVelocity -= 0.3f; if (knockbackVelocity < 0) { knockbackVelocity = 0; } } ServerSend.PlayerPosition(this); }
public void Update() //TODO: FIX MOVEMENT { //if (!atDestination) //{ // Vector2 inputDirection = Vector2.Zero; // if (destination.Y > position.Y) // { // inputDirection.Y += 1f; // } // if (destination.Y < position.Y) // { // inputDirection.Y -= 1f; // } // if (destination.X > position.X) // { // inputDirection.X += 1f; // } // if (destination.X < position.X) // { // inputDirection.X -= 1f; // } // Console.WriteLine(inputDirection); // Console.WriteLine("Destination:"); // Console.WriteLine(destination); // Move(inputDirection); //} if (position != destination) { isMoving = true; position = Vector3.Lerp(position, destination, startTime / duration); startTime += 0.001f; //Console.WriteLine("Walk"); //Console.WriteLine(startTime); //Console.WriteLine(startTime / duration); ServerSend.PlayerPosition(this); ServerSend.PlayerRotation(this); } if (position == destination) { isMoving = false; startTime = 0f; } }
private static void TCPConnectAsyncCallback(IAsyncResult asyncResult) { TcpClient client = TCPListener.EndAcceptTcpClient(asyncResult); TCPBeginAcceptClient(); Console.WriteLine($"\nUser {client.Client.RemoteEndPoint} is trying to connect..."); for (int count = 1; count < MaxNumPlayers + 1; count++) { if (ClientDictionary[count].tCP.Socket == null) { ClientDictionary[count].tCP.Connect(client); Console.WriteLine($"Sent welcome packet to: {count}"); ServerSend.Welcome(count, $"Welcome to the server client: {count}"); return; } } Console.WriteLine($"\nThe server is full... {client.Client.RemoteEndPoint} couldn't connect..."); }
public void JoinTheRoom(int _clientId) { if (playersInRoom.Count >= MaxPlayersInRoom) { //send net_mest return; } else { //sent _clientId ti v igre } int freePlace = FoundFreePlace(); if (freePlace < 0 && freePlace > MaxPlayersInRoom) { return; } Client client = Server.clients[_clientId]; // Player player = client.player; // Console.WriteLine($"JoinTheRoom " + client.username); playersInRoom.Add(freePlace, client); if (spectators.Contains(client)) { spectators.Remove(client); } int placeNum = freePlace;//= playersInRoom.IndexOf(client); ServerSend.NewPlayerJoins(client, placeNum); if (gameStatus == GameStatus.distribution) { gameStatus = GameStatus.start; } }