void LateUpdate()
    {
        if (!aimHead)
        {
            return;
        }

        if (components.pokemon.networkID == DarkRiftAPI.id)
        {
            desiredRotation = Quaternion.Euler(Camera.main.transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, 0.0f);

            if (transform.rotation != desiredRotation)
            {
                DarkRiftAPI.SendMessageToOthers(TagIndex.PokemonUpdate, TagIndex.PokemonUpdateSubjects.AimHead, desiredRotation);
            }

            transform.rotation = desiredRotation;

            return;
        }
        else
        {
            transform.rotation = desiredRotation;
        }
    }
    void ReceiveData(ushort senderID, byte tag, ushort subject, object data)
    {
        //Controller Tag
        if (tag == TagIndex.Controller && DarkRiftAPI.isConnected)
        {
            //If a player has joined tell them to give us a player
            if (subject == TagIndex.ControllerSubjects.JoinMessage)
            {
                //Tell them to spawn you
                DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, player.position);
                //Later we should use another one to assign the username
            }

            //Spawn the player
            if (subject == TagIndex.ControllerSubjects.SpawnPlayer && DarkRiftAPI.isConnected)
            {
                //Instantiate the player
                GameObject clone = (GameObject)Instantiate(playerObject, (Vector3)data, Quaternion.identity);
                Debug.Log("Spawned Player");
                //Tell the network player who owns it so it tunes into the right updates.
                clone.GetComponent <N_Movement>().networkID = senderID;

                //If it's our player being created allow control and set the reference
                if (senderID == DarkRiftAPI.id && DarkRiftAPI.isConnected)
                {
                    clone.GetComponent <N_Movement>().isMine = true;
                    player = clone.transform;
                }
            }
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (DarkRiftAPI.isConnected && DarkRiftAPI.id == networkID)
        {
            //Serialize if the position or rotation changes
            if (Vector3.Distance(lastPosition, transform.position) >= 1)
            {
                //DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Position, transform.position);
                SerialisePosA(transform.position);
                lastPosition = transform.position;
            }
            if (Quaternion.Angle(lastRotation, transform.rotation) > 45)
            {
                DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Rotation, transform.rotation);
            }
            //SerializeAnim();
            //Update stuff

            lastRotation = transform.rotation;
        }


        //Animation Settings
        anim.SetBool("IsRunning", plValues.running);
        anim.SetBool("IsGrounded", plValues.grounded);
        anim.SetInteger("State", plValues.state);
        anim.SetFloat("Speed", plValues.speed);
        anim.SetFloat("Horizontal", plValues.hor);
        anim.SetFloat("Vertical", plValues.ver);
    }
Exemple #4
0
 void OnApplicationQuit()
 {
     if (DarkRiftAPI.isConnected)
     {
         DarkRiftAPI.Disconnect();
     }
 }
Exemple #5
0
 private void OnInitiatedMelee()
 {
     if (DarkRiftAPI.isConnected && DarkRiftAPI.id == networkID)
     {
         DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.MeleeAttack, "pepitogrillo");
     }
 }
Exemple #6
0
 void Update()
 {
     if (DarkRiftAPI.isConnected)
     {
         DarkRiftAPI.Receive();
     }
 }
    //When the "Join" button is pressed
    public void LoadLevel()
    {
        string ip   = ipText.text;
        string user = usernameText.text;

        if (ip.Equals(""))
        {
            ip = "localhost";
        }
        if (user.Equals(""))
        {
            user = "******";
        }

        PlayerPrefs.SetString("Username", user);
        using (var writer = new StreamWriter(File.Create(autofillPath))) {
            writer.WriteLine(ip);
            writer.WriteLine(user);
            Debug.Log("Successfully wrote autofill.cfg");
        };

        Debug.Log("Attempting to connect to " + ip + " as " + user);
        try {
            DarkRiftAPI.Connect(ip);

            SceneManager.LoadScene("TestMap");
        } catch {
            errorText.text = "Could not connect to " + ip + ". Please verify that the ip is correct.";
            Debug.LogError(errorText.text);
            error.enabled = true;
        }
    }
    void Start()
    {
        //Enable Background Running
        Application.runInBackground = true;

        //Enable custom log
        CustomLogger.LogIt("Start Logging");
        //Application.dataPath
        Debug.Log(Application.dataPath);

        //Connect to the DarkRift Server using the Ip specified (will hang until connected or timeout)
        DarkRiftAPI.Connect(serverIP, serverPort);
        //Setup a receiver so we can create players when told to.
        DarkRiftAPI.onDataDetailed += ReceiveData;

        //Tell others that we've entered the game and to instantiate a player object for us.
        if (DarkRiftAPI.isConnected)
        {
            Debug.Log("Connected to the Server!");

            //Get everyone else to tell us to spawn them a player (this doesn't need the data field so just put whatever)
            DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.ControllerSubjects.JoinMessage, "hi");
            //Then tell them to spawn us a player! (this time the data is the spawn position)
            DarkRiftAPI.SendMessageToAll(TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, new Vector3(0f, 0f, 0f));
        }
        else
        {
            Debug.LogError("Failed to connect to DarkRift Server!");
        }
    }
    void SerialisePosRot(Vector3 pos, Quaternion rot, ushort ID, bool isVarKinematic)
    {
        //Here is where we actually serialise things manually. To do this we need to add
        //any data we want to send to a DarkRiftWriter. and then send this as we would normally.
        //The advantage of custom serialisation is that you have a much smaller overhead than when
        //the default BinaryFormatter is used, typically about 50 bytes.
        using (DarkRiftWriter writer = new DarkRiftWriter())
        {
            //Next we write any data to the writer
            writer.Write(isVarKinematic);
            writer.Write(pos.x);
            writer.Write(pos.y);
            writer.Write(pos.z);
            writer.Write(rot.x);
            writer.Write(rot.y);
            writer.Write(rot.z);
            writer.Write(rot.w);

            DarkRiftAPI.SendMessageToOthers(TagIndexVRTK.ObjectUpdate, ID, writer);
            if (DEBUG)
            {
                Debug.Log("Data sent: " + pos.ToString("F4") + " " + rot.ToString("F6"));
            }
        }
    }
Exemple #10
0
    public static void FlinchMessage(Pokemon target, Move moveUsed)
    {
        string targetsName = string.IsNullOrEmpty(target.nickname) ? target.pokemonName : target.nickname;
        string msg         = moveUsed.moveName + " caused " + targetsName + "(" + target.trainerName + ") to flinch!";

        DarkRiftAPI.SendMessageToAll(TagIndex.Chat, TagIndex.ChatSubjects.BattleChat, msg);
    }
Exemple #11
0
    public static void PartiallyTrappedMessage(Pokemon target, Move moveUsed)
    {
        string targetsName = string.IsNullOrEmpty(target.nickname) ? target.pokemonName : target.nickname;
        string msg         = targetsName + "(" + target.trainerName + ") was trapped by " + moveUsed.moveName + "!";

        DarkRiftAPI.SendMessageToAll(TagIndex.Chat, TagIndex.ChatSubjects.BattleChat, msg);
    }
Exemple #12
0
    private void ReceiveData(ushort senderID, byte tag, ushort subject, object data)
    {
        if (tag == TagIndex.Controller)
        {
            if (subject == TagIndex.ControllerSubjects.JoinMessage)
            {
                DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, localPlayer.transform.position);
            }

            if (subject == TagIndex.ControllerSubjects.SpawnPlayer)
            {
                GameObject clone = Instantiate(TrainerPrefabs[(int)trainerData.color], (Vector3)data, Quaternion.identity) as GameObject;

                clone.GetComponent <Trainer>().networkID = senderID;

                if (senderID == DarkRiftAPI.id)
                {
                    localPlayer             = clone.GetComponent <Trainer>();
                    localPlayer.localPlayer = true;
                    localPlayer.Init(trainerData);
                }
            }
        }
        if (tag == TagIndex.Chat)
        {
            if (subject == TagIndex.ChatSubjects.MainChat)
            {
                hud.AddToMainChat((string)data);
            }
            if (subject == TagIndex.ChatSubjects.BattleChat)
            {
                hud.AddToBattleChat((string)data);
            }
        }
    }
        public void CheckWinLose(WinLoseDraw cond)
        {
            if (GameHasStarted)
            {
                Debug.Log("Changing win lose text");
                switch (cond)
                {
                case WinLoseDraw.Draw:
                    WinLose.text = "DRAW";
                    DarkRiftAPI.SendMessageToAll(NetworkingTags.Controller, NetworkingTags.ControllerSubjects.GameOver, "");
                    break;

                case WinLoseDraw.Win:
                    WinLose.text = "YOU WIN";
                    DarkRiftAPI.SendMessageToAll(NetworkingTags.Controller, NetworkingTags.ControllerSubjects.GameOver, "");
                    break;

                case WinLoseDraw.Lose:
                    //DarkRiftAPI.SendMessageToServer(NetworkingTags.Server, NetworkingTags.ServerSubjects.ILose, "");
                    WinLose.text = "YOU LOSE";
                    break;
                }
                WinLose.gameObject.SetActive(true);
                GameHasStarted = false;
            }
        }
Exemple #14
0
    void ReceiveData(ushort senderID, byte tag, ushort subject, object data)
    {
        //When any data is received it will be passed here,
        //we then need to process it if it's got a tag of 0 and, if
        //so, create an object. This is where you'd handle most admin
        //stuff like that.

        //Ok, if data has a Controller tag then it's for us
        if (tag == TagIndex.Controller)
        {
            //If a player has joined tell them to give us a player
            if (subject == TagIndex.ControllerSubjects.JoinMessage)
            {
                //Basically reply to them.
                DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, player.position);
            }

            //Then if it has a spawn subject we need to spawn a player
            if (subject == TagIndex.ControllerSubjects.SpawnPlayer)
            {
                //Instantiate the player
                GameObject clone = (GameObject)Instantiate(playerObject, (Vector3)data, Quaternion.identity);
                //Tell the network player who owns it so it tunes into the right updates.
                clone.GetComponent <NetworkPlayer>().networkID = senderID;

                //If it's our player being created allow control and set the reference
                if (senderID == DarkRiftAPI.id)
                {
                    clone.GetComponent <Movement.PlayerMovement>().isControllable = true;
                    player = clone.transform;
                }
            }
        }
    }
Exemple #15
0
    // Checks if there is anything entered into the input field.
    public void LockInput(InputField input)
    {
        enterIP.SetActive(false);
        input.interactable = false;
        if (input.text.Length == 0)
        {
            Debug.Log("Text has been entered");
        }
        connecting.gameObject.SetActive(true);

        if (CustomNetworkManager.Instance.Connect(input.text))
        {
            //Debug.Log("Connection successful");
            connected.gameObject.SetActive(true);
            button.GetComponent <Button>().interactable = true;
            input.text = "";
            PlaceHolder.GetComponent <Text>().text = "";
            DarkRiftAPI.SendMessageToServer(Roland.NetworkingTags.Server, Roland.NetworkingTags.ServerSubjects.GetNumOfPlayers, "");
        }
        else
        {
            //Debug.Log("Connection failed");
            notConnected.gameObject.SetActive(true);
        }
        connecting.gameObject.SetActive(false);
    }
Exemple #16
0
    void Update()
    {
        //Only send data if we're connected and we own this player
        if (DarkRiftAPI.isConnected && DarkRiftAPI.id == networkID)
        {
            //We're going to use a tag of 1 for movement messages
            //If we're conencted and have moved send our position with subject 0.
            if (transform.position != lastPosition)
            {
                DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Position, transform.position);
            }
            //Then send our rotation with subject 1 if we've rotated.
            if (transform.rotation != lastRotation)
            {
                DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Rotation, transform.rotation);
            }

            //Update stuff
            lastPosition = transform.position;
            lastRotation = transform.rotation;
            //if ( Input.GetAxis("Fire1") > 0)
            if (Input.GetKeyDown("left ctrl"))
            {
                Debug.Log("fire1 axis down");
                string tmpstr = "EMOTION1";
                DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerMessage, TagIndex.PlayerMessageSubjects.Emotion, tmpstr);
            }
        }
    }
Exemple #17
0
 public static void RetrySendData()
 {
     if (DarkRiftAPI.isConnected)
     {
         DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.PlayerUpdate, prevUpdate);
         DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.PlayerUpdate, currUpdate);
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.C))
     {
         Debug.Log("Sending C");
         DarkRiftAPI.SendMessageToServer(Roland.NetworkingTags.Server, Roland.NetworkingTags.ServerSubjects.SendMeSomething, null);
     }
 }
 void OnApplicationQuit()
 {
     if (DarkRiftAPI.isConnected)
     {
         Debug.Log("Disconnectin");
         DarkRiftAPI.Disconnect();
     }
 }
 new void OnDestroy()
 {
     if (DarkRiftAPI.isConnected)
     {
         Debug.Log("Disconnectin");
         DarkRiftAPI.Disconnect();
     }
 }
Exemple #21
0
 void SendEventKeyboardDown(Direction theDir)
 {
     OnKeyboardButtonDown(theDir, client_id);
     if (DarkRiftAPI.isConnected)
     {
         DarkRiftAPI.SendMessageToAll(NetworkingTags.Events, NetworkingTags.EventSubjects.KeyboardEvent, theDir);
     }
 }
    public void SendChatMessage()
    {
        if (!string.IsNullOrEmpty(chatInput.text.Trim()))
        {
            DarkRiftAPI.SendMessageToAll(TagIndex.Chat, TagIndex.ChatSubjects.MainChat, chatInput.text);

            chatInput.text = string.Empty;
        }
    }
 void OnApplicationQuit()
 {
     if (DarkRiftAPI.isConnected)
     {
         Debug.Log("Disconnectin from room");
         DarkRiftAPI.onDataDetailed -= ReceiveData;
         DarkRiftAPI.Disconnect();
     }
 }
Exemple #24
0
 IEnumerator UpdatePosition()
 {
     while (true)
     {
         // DarkRiftAPI.SendMessageToOthers(NetworkingTags.Player, NetworkingTags.PlayerSubjects.ChangeBlockToNonMovable, currentTilePos);
         DarkRiftAPI.SendMessageToOthers(NetworkingTags.Player, NetworkingTags.PlayerSubjects.UpdatePostion, ourTransform.position);
         yield return(WaitForUpdate);
     }
 }
Exemple #25
0
    public static void SerialiseAnimBool(byte tagIndex, ushort subject, string stateName, bool value)
    {
        using (DarkRiftWriter writer = new DarkRiftWriter())
        {
            writer.Write(stateName);
            writer.Write(value);

            DarkRiftAPI.SendMessageToOthers(tagIndex, subject, writer);
        }
    }
Exemple #26
0
    void Start()
    {
        DarkRiftAPI.Connect(ip);

        LoginManager.onSuccessfulLogin   += ChangeToLogoutScreen;
        LoginManager.onUnsuccessfulLogin += MakeRed;
        LoginManager.onAddUser           += ChangeToLogoutScreen;
        LoginManager.onAddUserFailed     += MakeRed;
        LoginManager.onLogout            += ChangeToLoginScreen;
    }
        /// <summary>
        ///     Login with the specified username and password.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        public static void Login(string username, string password)
        {
            //Stop people from simply spamming the server
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return;
            }

            //Build the data to send
            using (DarkRiftWriter writer = new DarkRiftWriter())
            {
                writer.Write(username);
                writer.Write(SecurityHelper.GetHash(password, hashType));

                //Choose the connection to use
                if (connection == null)
                {
                    if (DarkRiftAPI.isConnected)
                    {
                        //Send via DarkRiftAPI
                        DarkRiftAPI.SendMessageToServer(
                            tag,
                            loginSubject,
                            writer
                            );

                        BindIfNotBound();
                    }
                    else
                    {
                        //Called if you try to login whilst not connected to a server
                        Debug.LogError("[LoginPlugin] You can't login if you're not connected to a server! (Do you mean to use DarkRiftAPI?)");
                    }
                }
                else
                {
                    if (connection.isConnected)
                    {
                        //Send via DarkRiftConnection
                        connection.SendMessageToServer(
                            tag,
                            loginSubject,
                            writer
                            );

                        BindIfNotBound();
                    }
                    else
                    {
                        //Called if you try to login whilst not connected to a server
                        Debug.LogError("[LoginPlugin] You can't login if you're not connected to a server!");
                    }
                }
            }
        }
 void MineExplosion()
 {
     theSrc.Play(theClipToPlayWhenExplode);
     DigSpawnTile(x, y, BombPower);
     DigSpawnTile(x + 1, y, BombPower);
     DigSpawnTile(x - 1, y, BombPower);
     DigSpawnTile(x, y + 1, BombPower);
     DigSpawnTile(x, y - 1, BombPower);
     DarkRiftAPI.SendMessageToOthers(NetworkingTags.Misc, NetworkingTags.MiscSubjects.MineExplode, Pos);
     Lean.LeanPool.Despawn(this.gameObject);
 }
 public bool Connect(string serverIP)
 {
     //Connect to the DarkRift Server using the Ip specified (will hang until connected or timeout)
     try {
         DarkRiftAPI.Connect(serverIP);
     }
     catch (ConnectionFailedException)
     {
         return(false);
     }
     return(true);
 }
    private void OnEnable()
    {
        ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
        //Network.player.ipAddress;
        string ip = GetIPAddress();

        //Debug.Log(Network.player.ipAddress);
        display_ip_address.text += " " + ip;
        DarkRiftAPI.onData      += Receive;
        DarkRiftAPI.Connect(ip);
        DarkRiftAPI.SendMessageToServer(Roland.NetworkingTags.Server, Roland.NetworkingTags.ServerSubjects.GetNumOfPlayers, 0);
    }