public static void Read(ServerBehaviour reader, int connectionID, DataStreamReader stream) { ClientMessage clientMessageType = (ClientMessage)stream.ReadByte(); //Debug.Log(reader.name + " got message of type " + clientMessageType.ToString()); switch (clientMessageType) { case ClientMessage.Pong: reader.ReadPong(connectionID); break; case ClientMessage.PlayerReady: reader.PlayerReady(connectionID); break; case ClientMessage.MovementInput: reader.ReadMovementInput(ExtractVector2(ref stream), connectionID); break; //case ClientMessage.ShootInput: // reader.ShootInput(connectionID, Convert.ToBoolean(stream.ReadByte())); // break; case ClientMessage.PlayerID: int val = stream.ReadInt(); reader.AssignPlayerIDToConnection(connectionID, val); break; default: break; } }
/// <summary> /// spawning the Hostbehaviour /// </summary> public void SpawnHost() { string name = playerName.text; if (name == string.Empty) { name = "Vincent #" + Mathf.RoundToInt(UnityEngine.Random.Range(0, 1000)); } GameObject go = new GameObject(); //adding serverbehaviour and set the playbutton onclick ServerBehaviour serverBehaviour = go.AddComponent <ServerBehaviour>(); UIManager.Instance.PlayButton.onClick.AddListener(serverBehaviour.StartGame); //clientbehaviour ClientBehaviour connect = go.AddComponent <ClientBehaviour>(); if (ipAdress.text == "") { serverBehaviour.IPAdress = ipAdress.text; connect.IPAdress = ipAdress.text; } go.name = "Server + Client"; connect.playerName = name; }
public virtual void Fire() { if (Cooldown.IsActive) { //Debug.Log(name + " is on cooldown.", this); return; } //Debug.Log("Fire " + name); if (Ammunition != null) { // Instantiate Projectile projectile = Instantiate(Ammunition, Muzzle.position, Muzzle.rotation); // Add force projectile.GetComponent <Rigidbody>()?.AddForce(GetComponentInParent <Rigidbody>().velocity *ParentVelocityInfluence + Muzzle.forward * ProjectileSpeed, forceMode); projectile.Owner = GetComponentInParent <Player>(); if (ServerBehaviour.HasActiveInstance()) { ServerBehaviour.Instance.projectiles.Add(projectile); } StartCoroutine(Cooldown.Start()); } }
protected virtual void Impact(Collision collisionData) { if (collisionData != null) { string output = ""; if (Owner != null) { if (!CanHitOwner) { if (collisionData.gameObject == Owner.gameObject) { Debug.Log(name + " can't hit owner " + Owner.name); return; } } output += Owner.name + " with "; } output += name; //Debug.Log(collisionData.gameObject.name + " was hit by " + output); Player playerHit = collisionData.gameObject.GetComponent <Player>(); if (playerHit != null) { //player.TakeDamage(Damage); if (Owner != null) { GameManager.Instance.PlayerTakesDamage(playerHit, Damage, Owner); } else { GameManager.Instance.PlayerTakesDamage(playerHit, Damage); } //player.Die(); } Health healthComponent = collisionData.collider.GetComponentInParent <Health>(); if (healthComponent != null) { healthComponent.UpdateValue(healthComponent.value - Damage); } } impactPosition = transform.position; hasImpacted = true; Explosive explosive = GetComponent <Explosive>(); if (explosive != null) { explosive.Explode(); } if (DisappearUponImpact) { if (ServerBehaviour.HasActiveInstance()) { ServerBehaviour.Instance.SendProjectileImpact(this); } //Debug.Log("Disappear"); gameObject.SetActive(false); } }
public void HostGame() { ServerBehaviour s = gameObject.AddComponent <ServerBehaviour>(); startGameButton.onClick.AddListener(ServerSend.StartGame); startGameButton.gameObject.SetActive(true); JoinGame(); }
public void Cmd_FinishRound() { ServerBehaviour server = GameObject.Find("GameServer").GetComponent <ServerBehaviour>(); if (server.state == GameState.Round) { didFire = true; server.FinishRound(ID); } }
// Cerco il referimento al Server public IEnumerator SearchSBCO() { while (refSB == null) { refSB = FindObjectOfType <ServerBehaviour>(); yield return(null); } Debug.Log("Ho trovato Server Behaviour"); yield break; }
private void OnCollisionEnter(Collision collision) { Player player = collision.collider.attachedRigidbody?.GetComponent <Player>(); if (ServerBehaviour.HasActiveInstance() && player != null && player != this) { Debug.Log("Found server behaviour: " + ServerBehaviour.Instance.name, ServerBehaviour.Instance); ServerBehaviour.Instance.PlayerCollision(); } }
private IEnumerator SearchSBCO() { while (refSB == null) { Debug.LogError("Non ho trovato refSB"); refSB = FindObjectOfType <ServerBehaviour>(); yield return(null); } Debug.LogError("Ho trovato refSB"); yield break; }
public static void SendAll(ServerMessage serverMessageType, ServerBehaviour sender) { if (!sender.m_Connections.IsCreated) { return; } for (int i = 0; i < sender.m_Connections.Length; i++) { Send(serverMessageType, sender, sender.m_Connections[i]); } }
private void Awake() { if (_instance != null && _instance != this) { Destroy(gameObject); } else { _instance = this; } DontDestroyOnLoad(gameObject); }
void Awake() { serverBehaviour = GetComponent <ServerBehaviour>(); serverBehaviour.addAvatar += AddAvatar; serverBehaviour.removeAvatars += RemoveAvatars; logManager = GetComponent <LogManager>(); //scoreCollection = new LookupCollection(); StartCoroutine("ScaleAvatarsBasedOnScore"); DontDestroyOnLoad(this); }
public static void Send(ServerMessage serverMessageType, ServerBehaviour sender, NetworkConnection receiver) { var writer = sender.m_Driver.BeginSend(receiver); writer.WriteByte((byte)serverMessageType); //Debug.Log("Send: " + serverMessageType.ToString() + " to " + receiver.InternalId); switch (serverMessageType) { case ServerMessage.Ping: case ServerMessage.TurnStart: case ServerMessage.TurnEnd: default: break; case ServerMessage.ConnectionID: WriteConnectionID(sender, ref writer, receiver); break; case ServerMessage.GameStart: writer.WriteInt(sender.m_Connections.Length); break; case ServerMessage.GameOver: WriteGameOver(sender, ref writer); break; case ServerMessage.ScoreUpdate: WriteScoreUpdate(sender, ref writer); break; case ServerMessage.PlayerTakesDamage: WritePlayerTakesDamage(sender, ref writer); break; case ServerMessage.PlayerPositions: WriteVector3ListToStream(sender.playerPositions, ref writer); break; case ServerMessage.PlayerRotations: WriteVector3ListToStream(sender.playerRotations, ref writer); break; case ServerMessage.ProjectilePositions: WriteVector3ListToStream(sender.projectilePositions, ref writer); break; //case ServerMessage.ProjectileImpact: // break; } sender.m_Driver.EndSend(writer); }
private void ServerWork() { try { // Application.DoEvents(); ServerBehaviour b = new ServerBehaviour(); b.MessageReceived += OnMessageReceived; //b.SessionCompleted += OnSessionCompleted; _server = new Server(b); _server.Run(); } catch (Exception exception) { using (StreamWriter newTask = new StreamWriter(ConfigurationManager.AppSettings["EmailFolderPath"] + "error.txt", false)) { newTask.WriteLine(exception.ToString()); } } }
public static void WriteScoreUpdate(ServerBehaviour sender, ref DataStreamWriter writer) { writer.WriteFloat(sender.latestDamageData.m_damage); }
private void Start() { server = GameObject.FindGameObjectWithTag("Server").GetComponent <ServerBehaviour>(); server.HostGameManager = this; }
public ServerManager() { serverBehaviour = new ServerBehaviour(this); game = new Game(this); }
private static void WritePlayerTakesDamage(ServerBehaviour sender, ref DataStreamWriter writer) { writer.WriteInt(sender.latestDamageData.m_receiver.ID); writer.WriteInt(sender.latestDamageData.m_dealer.ID); writer.WriteFloat(sender.latestDamageData.m_damage); }
void Awake() { serverBehaviour = GetComponent<ServerBehaviour>(); serverBehaviour.addAvatar += AddAvatar; serverBehaviour.removeAvatars += RemoveAvatars; logManager = GetComponent<LogManager>(); //scoreCollection = new LookupCollection(); DontDestroyOnLoad(this); }
public static void WriteGameOver(ServerBehaviour sender, ref DataStreamWriter writer) { writer.WriteInt(sender.PlayerIDWinner); writer.WriteInt(sender.PlayerIDSecond); writer.WriteInt(sender.WinnerScore); }
// Server: specialized Send functions public static void WriteConnectionID(ServerBehaviour sender, ref DataStreamWriter stream, NetworkConnection receiver) { stream.WriteInt(receiver.InternalId); }