Esempio n. 1
0
    //if theres a change in rotation
    private void OnRotationChange(int cnnID, NetworkStructs.RotationData data)
    {
        //NetworkStructs.DataPacket packet = new NetworkStructs.DataPacket(NetworkStructs.MessageTypes.CNN, NetworkStructs.getBytes(data));

        //send it to all players except the original sender of this message
        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.ROT, NetworkStructs.getBytes(data)), unreliableChannel, clients, cnnID);
    }
Esempio n. 2
0
    //when a player disconnects
    private void OnDisconnection(int cnnId)
    {
        //Remove this player from client list
        clients.Remove(clients.Find(x => x.connectionID == cnnId));

        NetworkStructs.IntData msg = new NetworkStructs.IntData(cnnId);

        //Tell everyone that somebody else has disconnected
        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.DC, NetworkStructs.getBytes(msg)), reliableChannel, clients);
    }
Esempio n. 3
0
    //when the player responds with their username
    private void OnNameIs(int cnnId, string playerName)
    {
        //Link name to connection ID
        clients.Find(x => x.connectionID == cnnId).playerName = playerName;

        NetworkStructs.NameRequestData msg = new NetworkStructs.NameRequestData(cnnId, playerName);

        //Tell everyone about new player connection
        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.CNN, NetworkStructs.getBytes(msg)), reliableChannel, clients);
    }
Esempio n. 4
0
    //send chat messages and admin commands
    public void sendMessage(string msg, int channelID)
    {
        if (msg.StartsWith("/"))
        {
            NetworkStructs.StringData message = new NetworkStructs.StringData(msg);
            Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.ADMIN, NetworkStructs.getBytes(message)), channelID);
        }
        else
        {
            msg = "[" + playerName + "]: " + msg;
            NetworkStructs.StringData message = new NetworkStructs.StringData(msg);

            Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.MESSAGE, NetworkStructs.getBytes(message)), channelID);
        }
    }
Esempio n. 5
0
    //update the position of the AI
    private void AIPositionUpdate()
    {
        //iterate through our dictionary to make sure we don't have any duplicates and to make sure each AI moves
        foreach (AI a in AIList.Values)
        {
            if (!a.switchBack)
            {
                //tells the AI to keep moving
                a.current = Vector3.MoveTowards(a.current, a.pos1, 0.01f);
                if (Vector3.Magnitude(a.current - a.pos1) < 0.1f)
                {
                    //tells the AI to swap directions
                    a.switchBack = true;
                }
            }
            else
            {
                //tells the AI to keep moving in the opposite direction of the above movement
                a.current = Vector3.MoveTowards(a.current, a.pos2, 0.01f);
                if (Vector3.Magnitude(a.current - a.pos2) < 0.1f)
                {
                    //tells the AI to swap directions again
                    a.switchBack = false;
                }
            }

            //send delay so we aren't sending it a shit ton of times per second
            if (sendDelay <= lastSent && clients.Count != 0)
            {
                lastSent = 0;

                NetworkStructs.AIMoveData msg = new NetworkStructs.AIMoveData(a.id, a.current);

                Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.MOVEAI, NetworkStructs.getBytes(msg)), unreliableChannel);
            }
            else
            {
                lastSent += Time.deltaTime;
            }
        }
    }
Esempio n. 6
0
    //handles the admin commands
    private void adminCommands(string msg, int cnnID)
    {
        if (msg.Contains("/setjump"))
        {
            //actually set the jump and output the change to the server log
            string number = msg.Substring(8);
            NetworkStructs.StringData data = new NetworkStructs.StringData("Setting player jump height to: " + number);
            serverConsole.AddToConsole("Setting player jump height to: " + number);
            Send(NetworkStructs.getBytes(data), reliableChannel, cnnID);

            //adds a number to the front of the message to function as a tag rather than setting up a whole new message type
            string messageToSend = "1";
            messageToSend += number;
            data           = new NetworkStructs.StringData(messageToSend);
            Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.ADMIN, NetworkStructs.getBytes(data)), reliableChannel);
        }
        else if (msg.Contains("/setspeed"))
        {
            //actually change the player speed and output the change to the server log
            string number = msg.Substring(9);
            NetworkStructs.StringData data = new NetworkStructs.StringData("Setting player move speed to: " + number);
            serverConsole.AddToConsole("Setting player move speed to: " + number);
            Send(NetworkStructs.getBytes(data), reliableChannel, cnnID);

            //adds a number to the front of the message to function as a tag rather than setting up a whole new message type
            string messageToSend = "2";
            messageToSend += number;
            data           = new NetworkStructs.StringData(messageToSend);
            Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.ADMIN, NetworkStructs.getBytes(data)), reliableChannel);
        }
        else
        {
            //send message to the server logs that the command doesn't exist, along with what the passed in command was
            NetworkStructs.StringData data = new NetworkStructs.StringData("Command: " + msg + " :Doesn't exist!");
            serverConsole.AddToConsole("Command: " + msg + " :Doesn't exist!");

            //this will send to just the player who sent the commnad (i think)
            Send(NetworkStructs.getBytes(data), reliableChannel, cnnID);
        }
    }
Esempio n. 7
0
    //when the server pings the player for their name
    private void OnAskName(NetworkStructs.NameRequestData data)
    {
        //set this clients ID
        ourClientId = data.id;

        NetworkStructs.StringData msg = new NetworkStructs.StringData(playerName);

        //Send our name to the server
        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.NAMEIS, NetworkStructs.getBytes(msg)), reliableChannel);

        string[] connectionList = data.str.Split('|');

        //Create all the other players
        for (int i = 0; i < connectionList.Length; ++i)
        {
            string[] d = connectionList[i].Split('%');
            if (int.Parse(d[1]) != ourClientId)
            {
                SpawnPlayer(d[0], int.Parse(d[1]));
            }
        }
    }
Esempio n. 8
0
    //when a player connects
    private void OnConnection(int cnnId)
    {
        // add connection to list
        ServerClient c = new ServerClient();

        c.connectionID = cnnId;
        c.playerName   = "TEMP";
        clients.Add(c);

        // when player joins give ID
        // request name and send name of other players
        string list = "";

        foreach (ServerClient sc in clients)
        {
            list += sc.playerName + '%' + sc.connectionID + "|";
        }
        list = list.Trim('|');

        NetworkStructs.NameRequestData msg = new NetworkStructs.NameRequestData(cnnId, list);

        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.ASKNAME, NetworkStructs.getBytes(msg)), reliableChannel, cnnId);
    }
Esempio n. 9
0
 //if theres a change in position
 private void OnMovement(int cnnID, NetworkStructs.PositionVelocityData data)
 {
     //send it to all players except the original sender of this message
     Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.MOVE, NetworkStructs.getBytes(data)), unreliableChannel, clients, cnnID);
 }
Esempio n. 10
0
    //setup the AI that are running on the local machine
    public void SetupAI(int id, Vector3 pos1, Vector3 pos2)
    {
        NetworkStructs.AIInitialMoveData msg = new NetworkStructs.AIInitialMoveData(id, pos1, pos2);

        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.SETUPAI, NetworkStructs.getBytes(msg)), reliableChannel);
    }
Esempio n. 11
0
    //send the local player's movement
    public void SendMovement(Vector3 pos, Vector3 vel)
    {
        NetworkStructs.PositionVelocityData msg = new NetworkStructs.PositionVelocityData(ourClientId, pos, vel);

        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.MOVE, NetworkStructs.getBytes(msg)), unreliableChannel);
    }
Esempio n. 12
0
    //send the local player's rotation
    public void SendRotation(float xRot, float yRot)
    {
        NetworkStructs.RotationData msg = new NetworkStructs.RotationData(ourClientId, xRot, yRot);

        Send(NetworkStructs.AddTag(NetworkStructs.MessageTypes.ROT, NetworkStructs.getBytes(msg)), unreliableChannel);
    }