public void UpdateClientStats(ClientDataOnServer clientData)
        {
            MsgClientStatsUpdate update = new MsgClientStatsUpdate()
            {
                CurrentHealth = clientData.CurrentHealth, KillCount = clientData.KillCount, DeathCount = clientData.DeathCount, CaptureCount = clientData.CaptureCount, EXP = clientData.EXP
            };
            string serializedMessage = JsonUtility.SerializeToJson <MsgClientStatsUpdate>(update);

            networkView.RPC(RPCFunctions.RPC_UPDATE_CLIENT_STATS, clientData.NetworkPlayer, serializedMessage);
        }
 private void OnTriggerEnter(Collider cCollider)
 {
     if (Network.isServer)
     {
         ServerManager      cServer = RoleManager.roleManager as ServerManager;
         ClientDataOnServer client  = serverManager.RegisteredClients.First(c => c.NetworkPlayer == networkView.owner);
         // Check if collided with the flag.
         if (cCollider.name == Names.NAME_FLAG)
         {
             Network.Destroy(cCollider.gameObject);
             HasFlag = true;
             // Send message to the server manager.
             cServer.SendGameMessage(new MsgFlagPickedUp()
             {
                 PlayerName = client.Profile.DisplayName
             });
         }
     }
 }
        private void CollidedWithBase(ClientDataOnServer client)
        {
            if (Network.isServer)
            {
                ServerManager cServer = RoleManager.roleManager as ServerManager;

                if (HasFlag == true)
                {
                    // Inform the server that we delivered the flag to the base.
                    cServer.SendGameMessage(new MsgFlagDelivered()
                    {
                        PlayerName = client.Profile.DisplayName, PlayerTeam = client.ClientTeam
                    });
                    HasFlag = false;
                    CSpawner.SpawnFlag();
                }

                cServer.SendGameMessage(new PlayerHealed()
                {
                    Heal = 1
                });
            }
        }
Esempio n. 4
0
        public bool RegisterClient(RegisterClient registerMessage, out IAIBase.ETeam team, out int teamOrder)
        {
            if (registeredClients.Count < Constants.GAME_MAX_PLAYERS)
            {
                team = GetTeamForNextClient(out teamOrder);

                ClientDataOnServer client = new ClientDataOnServer(registerMessage.User, registerMessage.Profile, registerMessage.NetworkPlayer, team);
                registeredClients.Add(client);

                if (OnClientRegistered != null)
                {
                    OnClientRegistered();
                }

                return(true);
            }
            else
            {
                Debug.LogError("Maximum number of players reached, cannot register");
                team      = IAIBase.ETeam.TEAM_NONE;
                teamOrder = -1;
                return(false);
            }
        }
        private void OnCollisionEnter(Collision cCollision)
        {
            // Only react on server and results will be send to client when processed
            if (Network.isServer)
            {
                // Get a handle on the gameObject with which we collided.
                GameObject goObject = cCollision.gameObject;

                // Check if we collided with a base
                if (goObject.tag == Tags.TAG_BASE)
                {
                    ClientDataOnServer client = serverManager.RegisteredClients.First(c => c.NetworkPlayer == networkView.owner);

                    if (goObject.name == Names.NAME_RED_BASE && client.ClientTeam == IAIBase.ETeam.TEAM_RED)
                    {
                        CollidedWithBase(client);
                    }
                    else if (goObject.name == Names.NAME_BLUE_BASE && client.ClientTeam == IAIBase.ETeam.TEAM_BLUE)
                    {
                        CollidedWithBase(client);
                    }
                }

                // Depending on the name of the object, react accordingly.
                switch (goObject.tag)
                {
                case Tags.TAG_WEAPON:

                    // Get the name and team of the attacker using its projectile.
                    CProjectile cProjectile = goObject.GetComponent <CProjectile>();

                    if (null == cProjectile.Instantiator.gameObject)
                    {
                        return;
                    }

                    //// Set the name.
                    string        strAttackerName = "";
                    IAIBase.ETeam eTeam           = IAIBase.ETeam.TEAM_NONE;

                    // Check if attacker is another client
                    GameObject       goAttacker = cProjectile.Instantiator;
                    PlayerController aPC        = goAttacker.GetComponent <PlayerController>();
                    if (aPC != null)
                    {
                        ClientDataOnServer cd = serverManager.RegisteredClients.First(c => c.NetworkPlayer == aPC.networkView.owner);
                        strAttackerName = cd.Profile.DisplayName;
                        eTeam           = cd.ClientTeam;
                    }
                    else     // attacker is an AI
                    {
                        strAttackerName = "AI";
                        //// Find the team using the attacker's name.
                        if (strAttackerName == Names.NAME_AI_DRONE_BLUE + "(Clone)")
                        {
                            eTeam = IAIBase.ETeam.TEAM_BLUE;
                        }

                        else if (strAttackerName == Names.NAME_AI_DRONE_RED + "(Clone)")
                        {
                            eTeam = IAIBase.ETeam.TEAM_RED;
                        }
                    }

                    serverManager.SendGameMessage(new PlayerTakenDamage()
                    {
                        Player = networkView.owner, PlayerPosition = transform.position, Damage = (int)cProjectile.Damage, Attacker = strAttackerName, AttackerTeam = eTeam
                    });

                    break;
                }
            }
        }