Exemple #1
0
 private void FixedUpdate()
 {
     if (MyInfo.mapEditor == true && networking.GetComponent <Networking>().mapEditor == true)
     {
         Rater193.LocalPlayerFixedUpdate(this);
     }
 }
Exemple #2
0
 private void Start()
 {
     player = GetComponent <Rigidbody2D>();
     InvokeRepeating("SendPosition", 0.05f, 0.05f);
     InvokeRepeating("SendLook", 0.05f, 0.05f);
     Rater193.LocalPlayerStart(this);
 }
 static void Main(string[] args)
 {
     ////////////////////////////////////
     //rater193-edit: Event hook!
     Rater193.Init(args);
     ////////////////////////////////////
     StartServer();
 }
Exemple #4
0
    public void HandleDataServer(NetIncomingMessage data)
    {
        switch (data.ReadByte())
        {
        case 1:                 //WORLD
            switch (data.ReadByte())
            {
            case 1:                             //SPAWNING
                switch (data.ReadByte())
                {
                case 1:                                         //SPAWN SELF
                    GetComponent <World>().SpawnSelf();
                    break;

                case 2:                                         //SPAWN OTHER
                    int playerId = data.ReadInt32();
                    if (playerId != MyInfo.playerId)
                    {
                        GetComponent <World>().SpawnOther(playerId, data.ReadString(), data.ReadInt32(), data.ReadInt32(), data.ReadString(), data.ReadString(), data.ReadString(), data.ReadFloat(), data.ReadFloat());
                    }
                    break;

                case 3:                                         //REMOVE OTHER
                    GetComponent <World>().RemovePlayer(data.ReadInt32());
                    break;
                }
                break;

            case 2:                             //PLAYER
                switch (data.ReadByte())
                {
                case 1:                                         //POSITION
                    GetComponent <World>().SetPlayerPosition(data.ReadInt32(), data.ReadBoolean(), data.ReadFloat(), data.ReadFloat());
                    break;

                case 2:                                         //LOOK
                    GetComponent <World>().SetPlayerLook(data.ReadInt32(), data.ReadFloat(), data.ReadBoolean());
                    break;
                }
                break;

            case 9:                             //CHAT
                GetComponent <World>().ChatMessage(data.ReadByte(), data.ReadInt32(), data.ReadString(), data.ReadString());
                break;

            case (byte)255:
                Rater193.handleData(data);
                break;
            }
            break;
        }
    }
Exemple #5
0
    public void SpawnSelf()
    {
        GameObject player = (GameObject)Instantiate(Resources.Load("Prefabs/Player/Player"));

        MyInfo.player = player;
        player.GetComponent <PlayerControl>().networking = gameObject;
        player.GetComponent <SetPlayer>().SetInfo(MyInfo.username, MyInfo.skinColour, MyInfo.hairColour, MyInfo.clothingColour, 0, 0);

        Rater193.networking = gameObject.GetComponent <Networking>();
        Rater193.Init();
        chatBox = GameObject.Find("Canvas/Chatbox");
        chatBox.GetComponent <ChatboxControl>().mapEditor = GetComponent <Networking>().mapEditor;
    }
Exemple #6
0
    private void Update()
    {
        //Camera.main.transform.position = new Vector3(player.position.x, player.position.y, Camera.main.transform.position.z);

        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical   = Input.GetAxisRaw("Vertical");

        Movement(horizontal, vertical);
        MoveAnimation(horizontal, vertical);

        if (MyInfo.mapEditor == true && networking.GetComponent <Networking>().mapEditor == true)
        {
            Rater193.LocalPlayerUpdate(this);
        }
    }
        private static void StartServer()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("MMO");

            config.Port = 8001;
            config.MaximumConnections = 100;
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            server = new NetServer(config);
            server.Start();

            Console.ForegroundColor = logColour;
            Console.Write("CLIENTS CONNECTED: " + clientList.Count);
            Console.WriteLine("");
            Console.ForegroundColor = ConsoleColor.White;

            config       = new NetPeerConfiguration("MMO");
            serverClient = new NetClient(config);
            serverClient.Start();
            NetOutgoingMessage message = serverClient.CreateMessage();

            message.Write((byte)1);             //CONNECT
            serverClient.Connect("127.0.0.1", 8002, message);

            Thread thread = new Thread(ConsoleCommand);

            thread.Start();

            var startTimeSpan  = TimeSpan.Zero;
            var periodTimeSpan = TimeSpan.FromSeconds(5);
            var timer          = new Timer((e) => { Ping(); }, null, startTimeSpan, periodTimeSpan);

            while (shutdown == false)
            {
                Rater193.Update();
                Listen();
            }
            Rater193.Shutdown();

            serverClient.Disconnect("Quit");
            Thread.Sleep(250);
            Environment.Exit(0);
        }
Exemple #8
0
        public static void HandleClient(Client client, NetIncomingMessage data)
        {
            switch (data.ReadByte())
            {
            case 1:                     //PING
                client.timeoutTimer.Stop();
                client.timeoutTimer.Start();
                break;

                #region World data
            case 2:                     //WORLD
                switch (data.ReadByte())
                {
                case 1:                                 //JOINED WORLD
                    NetOutgoingMessage message = RegionalServer.server.CreateMessage();
                    message.Write((byte)1);             //WORLD
                    message.Write((byte)1);             //SPAWNING
                    message.Write((byte)1);             //SPAWN SELF
                    RegionalServer.server.SendMessage(message, client.connection, NetDeliveryMethod.ReliableOrdered, 0);

                    for (int i = 0; i < RegionalServer.clientList.Count; i++)
                    {
                        Client client_ = RegionalServer.clientList[i];
                        if (client_ != client)
                        {
                            //Sending self to other clients
                            message = RegionalServer.server.CreateMessage();
                            message.Write((byte)1);                                             //WORLD
                            message.Write((byte)1);                                             //SPAWNING
                            message.Write((byte)2);                                             //SPAWN OTHER
                            message.Write(client.clientId);
                            message.Write(client.username);
                            message.Write(client.authority);
                            message.Write(client.level);
                            message.Write(client.skinColour);
                            message.Write(client.hairColour);
                            message.Write(client.clothingColour);
                            message.Write(client.playerPosX);
                            message.Write(client.playerPosY);
                            RegionalServer.server.SendMessage(message, client_.connection, NetDeliveryMethod.ReliableOrdered, 0);

                            //sending other clients to self
                            message = RegionalServer.server.CreateMessage();
                            message.Write((byte)1);                                             //WORLD
                            message.Write((byte)1);                                             //SPAWNING
                            message.Write((byte)2);                                             //SPAWN OTHER
                            message.Write(client_.clientId);
                            message.Write(client_.username);
                            message.Write(client_.authority);
                            message.Write(client_.level);
                            message.Write(client_.skinColour);
                            message.Write(client_.hairColour);
                            message.Write(client_.clothingColour);
                            message.Write(client_.playerPosX);
                            message.Write(client_.playerPosY);
                            RegionalServer.server.SendMessage(message, client.connection, NetDeliveryMethod.ReliableOrdered, 0);
                        }
                    }
                    Debug.Log("Send map");
                    //Triggering rater193's event to handle maps!
                    Rater193.onPlayerJoined.Invoke(client);
                    break;

                case 2:                                 //PLAYER
                    switch (data.ReadByte())
                    {
                        #region Player position
                    case 1:                                             //POSITION
                        bool    illegalPos = false;
                        float[] position   = new float[2] {
                            data.ReadFloat(), data.ReadFloat()
                        };
                        client.posHistory.RemoveAt(0);
                        client.posHistory.Add(position);
                        float[] pos1  = client.posHistory[0];
                        float[] pos2  = client.posHistory[1];
                        float   posX1 = pos1[0];
                        float   posY1 = pos1[1];
                        float   posX2 = pos2[0];
                        float   posY2 = pos2[1];

                        double distance = Math.Sqrt(Math.Pow(posX2 - posX1, 2) + Math.Pow(posY2 - posY1, 2));
                        if (distance <= client.playerStepMargin)
                        {
                            client.playerPosX = posX2;
                            client.playerPosY = posY2;
                        }
                        else
                        {
                            client.playerPosX    = posX1;
                            client.playerPosY    = posY1;
                            client.posHistory[0] = new float[2] {
                                posX1, posY1
                            };
                            client.posHistory[1] = new float[2] {
                                posX1, posY1
                            };
                            illegalPos = true;
                        }

                        for (int i = 0; i < RegionalServer.clientList.Count; i++)
                        {
                            Client client_ = RegionalServer.clientList[i];
                            if (client_.connection != null)
                            {
                                message = RegionalServer.server.CreateMessage();
                                message.Write((byte)1);                                                         //WORLD
                                message.Write((byte)2);                                                         //PLAYER
                                message.Write((byte)1);                                                         //POSITION
                                message.Write(client.clientId);
                                message.Write(illegalPos);
                                message.Write(client.playerPosX);
                                message.Write(client.playerPosY);
                                RegionalServer.server.SendMessage(message, client_.connection, NetDeliveryMethod.Unreliable, 0);
                            }
                        }
                        break;

                        #endregion
                        #region Player looking
                    case 2:                                             //ROTATION
                        for (int i = 0; i < RegionalServer.clientList.Count; i++)
                        {
                            Client client_ = RegionalServer.clientList[i];
                            if (client_ != client && client_.connection != null)
                            {
                                message = RegionalServer.server.CreateMessage();
                                message.Write((byte)1);                                                         //WORLD
                                message.Write((byte)2);                                                         //PLAYER
                                message.Write((byte)2);                                                         //POSITION
                                message.Write(client.clientId);
                                message.Write(data.ReadFloat());
                                message.Write(data.ReadBoolean());
                                RegionalServer.server.SendMessage(message, client_.connection, NetDeliveryMethod.Unreliable, 0);
                            }
                        }
                        break;
                        #endregion
                    }
                    break;

                case 9:                                 //CHAT
                    for (int i = 0; i < RegionalServer.clientList.Count; i++)
                    {
                        byte mode = data.ReadByte();
                        switch (mode)
                        {
                        case 1:                                                 //ALL
                            message = RegionalServer.server.CreateMessage();
                            message.Write((byte)1);                             //WORLD
                            message.Write((byte)9);                             //CHAT
                            message.Write(mode);
                            message.Write(client.authority);
                            message.Write(client.username);
                            message.Write(data.ReadString());
                            RegionalServer.server.SendMessage(message, RegionalServer.clientList[i].connection, NetDeliveryMethod.Unreliable, 0);
                            break;

                        case 2:                                                 //GLOBAL
                            message = RegionalServer.server.CreateMessage();
                            message.Write((byte)1);                             //WORLD
                            message.Write((byte)9);                             //CHAT
                            message.Write(mode);
                            message.Write(client.authority);
                            message.Write(client.username);
                            message.Write(data.ReadString());
                            RegionalServer.server.SendMessage(message, RegionalServer.clientList[i].connection, NetDeliveryMethod.Unreliable, 0);
                            break;
                        }
                    }
                    break;

                    #region rater193's handler
                case 255:
                    Rater193.HandleData(client, data);
                    break;
                    #endregion
                }
                break;
                #endregion
            }
        }