Esempio n. 1
0
    public void ClientDisconnected(NetworkMessage netMsg)
    {
        Debug.Log("Client disconnected. " + netMsg.conn.connectionId);
        Callipso.GameSession _s = sessions.Find(x => (x.agents.Find(e => e.user != null && e.user.connectionId == netMsg.conn.connectionId)));         // currently in session

        if (_s != null)
        {
            _s.KickPlayer(netMsg.conn.connectionId);          // remove the connection from the session
        }
    }
Esempio n. 2
0
    public void SkillRequest(NetworkMessage netMsg)
    {
        Callipso.GameSession _currentSession = sessions.Find(x => x.agents.Find(e => e.user != null && e.user.connectionId == netMsg.conn.connectionId)); // currently in session
        if (_currentSession == null || !_currentSession.isStarted)
        {                                                                                                                                                 // Not in a session or session is not started
            netMsg.conn.Disconnect();
            return;
        }

        _currentSession.SkillRequest(netMsg.conn.connectionId, netMsg.ReadMessage <MObjects.SkillRequest>().skillId);
    }
Esempio n. 3
0
    public static MobileAgent SpawnPlayerBot(string clientPrefab, Callipso.GameSession session)
    {
        MobileAgent created = ServerManager.current.JoinGame(null, session, _botNames.list [Random.Range(0, _botNames.list.Count)], null, true);
        AIAgent     ai      = created.gameObject.AddComponent <AIAgent>();

        ai.agent     = created;
        ai.vision    = 20;
        created.user = null;

        return(created);
    }
Esempio n. 4
0
    public void LastAim(NetworkMessage netMsg)
    {
        Callipso.GameSession _currentSession = sessions.Find(x => x.agents.Find(e => e.user != null && e.user.connectionId == netMsg.conn.connectionId)); // currently in session
        if (_currentSession == null || !_currentSession.isStarted)
        {                                                                                                                                                 // Not in a session or session is not started
            netMsg.conn.Disconnect();
            return;
        }

        MObjects.LastAim mObject = netMsg.ReadMessage <MObjects.LastAim>();
        _currentSession.LastAim(netMsg.conn.connectionId, mObject.y, mObject.pos);
    }
Esempio n. 5
0
    public void HeroChangeRequest(NetworkMessage netMsg)
    {
        Callipso.GameSession _currentSession = sessions.Find(x => x.agents.Find(e => e.user != null && e.user.connectionId == netMsg.conn.connectionId)); // currently in session
        if (_currentSession == null || _currentSession.isStarted)
        {                                                                                                                                                 // Not in a session or session is not started
            netMsg.conn.Disconnect();
            return;
        }

        MObjects.HeroChangeRequest mObject = netMsg.ReadMessage <MObjects.HeroChangeRequest>();
        _currentSession.HeroChange(netMsg.conn.connectionId, mObject.val);
    }
Esempio n. 6
0
    public static MobileAgent SpawnCreature(string clientPrefab, Callipso.GameSession session)
    {
        Callipso.Hero creature = ServerManager.creatureHeroes.Find(x => x.clientPrefab == clientPrefab);
        MobileAgent   created  = ServerManager.current.JoinGame(null, session, creature.alias, clientPrefab);
        AIAgent       ai       = created.gameObject.AddComponent <AIAgent>();

        ai.agent     = created;
        ai.vision    = creature.vision; // Bots always can see
        created.user = null;

        return(created);
    }
Esempio n. 7
0
    public Vector3 Request_SpawnPoint(Callipso.GameSession session, ushort team)
    {
        if (teamsize == 0) // 0 = deathmath
        {
            team = 0;
        }

        session.spawnPointRequester[team]++;

        if (session.spawnPointRequester[team] >= teamData[team].spawnPoints.Length)
        {
            session.spawnPointRequester[team] = 0;
        }
        return(teamData[team].spawnPoints [session.spawnPointRequester[team]]);
    }
Esempio n. 8
0
    public static void FindCollision(ushort sessionId, Vector3 pos, float radius, out List <MobileAgent> found)
    {
        Callipso.GameSession _gameSession = ServerManager.sessions.Find(x => x.id == sessionId);

        found = new List <MobileAgent>();

        if (_gameSession == null)
        {
            return; // Session not found
        }
        List <MobileAgent> alives = _gameSession.agents.FindAll(x => x.health > 0);
        int agentCount            = alives.Count;

        for (int i = 0; i < agentCount; i++)
        {
            if (GetDistance(pos, alives[i].transform.position) - alives[i].physik.radius / 2 <= radius)
            {
                found.Add(alives[i]);
            }
        }
    }
Esempio n. 9
0
    public void FindGameRequest(NetworkMessage netMsg) // Registered on UNETServer
    {
        Debug.Log("Find game request received");

        /*
         * FIND THE CURRENT SESSION
         * */
        MObjects.FindGameRequest mObject = netMsg.ReadMessage <MObjects.FindGameRequest>();

        Callipso.GameSession _currentSession = sessions.Find(x => x.agents.Find(e => e.user != null && e.user.connectionId == netMsg.conn.connectionId)); // currently in session
        if (_currentSession != null)
        {
            netMsg.conn.Disconnect();
            return;
            // kicked
        }

        string clientPrefab = playerHeroes[Random.Range(0, playerHeroes.Count)].clientPrefab;  // Random hero for first connection

        Callipso.GameSession _gameSession = sessions.Find(x => x.map == mObject.mapId && !x.isStarted && !x.killed && x.agents.Count < MapLoader.maps [x.map].maxPlayers);
        JoinGame(netMsg.conn, _gameSession, mObject.alias, clientPrefab, true, mObject.mapId);
    }
Esempio n. 10
0
    public MobileAgent JoinGame(NetworkConnection conn, Callipso.GameSession _gameSession, string alias, string clientPrefab = null, bool isHero = false, ushort mapId = 0)
    {
        if (conn != null)
        {
            SendHeroInfo(conn); // Send hero list
        }
        if (_gameSession == null)
        {         // No game found creating session
            Debug.Log("Creating game session");
            _gameSession     = new Callipso.GameSession();
            _gameSession.id  = createdSessions++;
            _gameSession.map = mapId;

            int cSpawns = MapLoader.maps[_gameSession.map].creatureSpawns.Count;
            _gameSession.creatureSpawns = new float[cSpawns];

            _gameSession.round    = 1;
            _gameSession.time     = Time.time + MapLoader.maps[_gameSession.map].lobbyTime;
            _gameSession.teamsize = MapLoader.maps[_gameSession.map].teamsize;

            sessions.Add(_gameSession);
        }
        else
        {
            Debug.Log("Joining game session");
        }

        GameObject  _player = new GameObject("Player");
        MobileAgent _ma     = _player.AddComponent <MobileAgent>();

        _ma.agentLevel         = _player.AddComponent <MobileAgent_Leveling>();
        _ma.agentLevel.myAgent = _ma;
        _ma.agentBuff          = _player.AddComponent <MobileAgent_Buffs>();
        _ma.agentBuff.myAgent  = _ma;

        _ma.session = _gameSession;

        _ma.user = conn;

        if (_ma.user != null)
        {
            _ma.session.users.Add(conn);
        }

        if (_ma.user == null)
        {
            _ma.customId = (short)(-(_gameSession.agentCreated++) - 1);
        }
        _ma.alias = alias;                   // set user alias

        SpamController.obj.SpamFor(_ma, 10); // client can send this per two seconds or the spammer will be increased (10/5)

        _gameSession.agents.Add(_ma);

        _ma.LoadHero(clientPrefab, isHero);         // for bots

        if (_ma._hero.heroType == Callipso.HeroType.Player && _gameSession.time < Time.time + 10)
        {         // New player joined
            _gameSession.time = Time.time + Mathf.Clamp(10, 0, MapLoader.maps [_gameSession.map].lobbyTime);
        }

        _gameSession.Update(true);
        _ma.agentLevel.UpdateLevel(); // send the level info

        return(_ma);
    }