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!");
        }
    }
示例#2
0
    //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;
        }
    }
示例#3
0
    void Start()
    {
        DarkRiftAPI.Connect(ip);

        LoginManager.onSuccessfulLogin   += ChangeToLogoutScreen;
        LoginManager.onUnsuccessfulLogin += MakeRed;
        LoginManager.onAddUser           += ChangeToLogoutScreen;
        LoginManager.onAddUserFailed     += MakeRed;
        LoginManager.onLogout            += ChangeToLoginScreen;
    }
 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);
    }
示例#6
0
    public void TryToConnect()
    {
        if (DarkRiftAPI.isConnected)
        {
            return;
        }
        string sd = GameObject.Find("InputField").GetComponentsInChildren <Text>()[1].text;

        if (sd == "")
        {
            sd = serverIP;
        }
        if (!DarkRiftAPI.Connect(sd, 4296))
        {
            return;
        }
        GameObject go = GameObject.Find("Name1");

        //go.GetComponent<UnityEngine.UI.InputField>().text = "chiucken";
        Application.runInBackground = true;
        DarkRiftAPI.onDataDetailed += ReceiveData;

        DontDestroyOnLoad(transform.gameObject);

        if (DarkRiftAPI.isConnected)
        {
            DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.ControllerSubjects.JoinMessage, "hi");
            DarkRiftAPI.SendMessageToAll(TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, new Vector3(0.0f, 0.0f, 0.0f));
            int index = DarkRiftAPI.id - 1;
            GameObject.Find("Canvas").GetComponentsInChildren <Image>()[index].color = Color.white;
            if (DarkRift.DarkRiftAPI.id != 1)
            {
                GameObject.Find("Button").GetComponentsInChildren <Button>()[index].interactable = false;
            }
        }
        else
        {
            Debug.Log("Failed to connect to DarkRift Server!");
        }

        int id = playerNumber = DarkRiftAPI.id;

        if (id > playerCount)
        {
            playerCount = id;
        }

        SendData(TagIndex.Controller, TagIndex.PlayerUpdate, factions[DarkRiftAPI.id - 1]);
    }
示例#7
0
    void Start()
    {
        //Connect to the DarkRift Server using the Ip specified (will hang until connected or timeout)
        DarkRiftAPI.Connect(serverIP);

        //Setup a reciever so we can create players when told to.
        DarkRiftAPI.onDataDetailed += RecieveData;

        //Tell others that we've entered the game and to instantiate a player object for us.
        if (DarkRiftAPI.isConnected)
        {
            //Get everyone else to tell us to spawn them a player (this doesnt 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));
        }
    }
示例#8
0
    /*******************************************************************
     * Method used for initialization
     ******************************************************************/
    void Start()
    {
        // connect to the DarkRift server at IP and port
        DarkRiftAPI.Connect(IP, port);

        // assign onDataRecieved function to the onData event so it
        // runs every time data is recieved from the server.
        DarkRiftAPI.onData += onDataReceived;

        // send the request for item and note data to spawn on the level
        // server can only reply to a specific client so the client has to
        // send the first message.
        if (DarkRiftAPI.isConnected)
        {
            Debug.Log("Sending data request.");
            DarkRiftAPI.SendMessageToServer(0, (ushort)clientID, "RequestData");
        }
        else
        {
            Debug.Log("Failed to connect to DarkRift Server!");
        }
    }
示例#9
0
    public IEnumerator JoinServer(Text messageText)
    {
        hud.loadingPanel.SetActive(true);
        hud.gameObject.SetActive(true);

        int port = 4296;

        if (trainerData.lastZone == "Pallet Town")
        {
            port = PortIndex.PalletTown;
        }
        else if (trainerData.lastZone == "Route One")
        {
            port = PortIndex.RouteOne;
        }

        DarkRiftAPI.Connect(serverIP, port);

        if (DarkRiftAPI.isConnected)
        {
            DarkRiftAPI.onDataDetailed += ReceiveData;
        }
        else
        {
            messageText.text = "Failed to connect to the server!";

            StopCoroutine(JoinServer(messageText));
        }

        SceneManager.sceneLoaded += OnLevelFinishedLoading;
        async = SceneManager.LoadSceneAsync(trainerData.lastZone);

        while (!async.isDone)
        {
            loadingProgress.text = (async.progress * 100.0f).ToString() + "%";
            yield return(null);
        }
    }
示例#10
0
 //GUI Stuff for connecting
 private void OnGUI()
 {
     GUILayout.BeginArea(new Rect(Screen.width / 2 - 100, 0, 200, 150));
     //If the player hasn't connected yet, allow the player to connect
     if (!DarkRiftAPI.isConnected)
     {
         _IP = GUILayout.TextField(_IP);
         if (GUILayout.Button("Connect"))
         {
             DarkRiftAPI.Connect(_IP);
             //Connect to the DarkRift server hosted on the machine with _IP IP Address
         }
     }
     if (!DoVisualize)
     {
         Texture2D tex = new Texture2D(1, 1);
         tex.SetPixel(1, 1, new Color32(255, 255, 255, 255));
         GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), tex);
         GUILayout.Label("Catching up", Style);
     }
     GUILayout.Label("Step Count: " + StepCount.ToString(), Style);
     GUILayout.EndArea();
 }
示例#11
0
 void Start()
 {
     Debug.Log(DarkRiftAPI.Connect(IP));
 }
 void Start()
 {
     DarkRiftAPI.Connect(IP);
 }
示例#13
0
    /*******************************************************************
     * Method to determine what to do when the application stops.
     ******************************************************************/
    void OnApplicationQuit()
    {
        // connect to the server
        DarkRiftAPI.Connect(IP, port);

        List <GameObject> goList = new List <GameObject> ();
        bool skip = false;

        // grab all the GameObjects in the level
        GameObject[] temp = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));

        // find the GameObjects that represent items and put them in the goList
        foreach (GameObject go in temp)
        {
            // if the gameObject has both ItemData and a SpriteRenderer then it's an item on the floor
            // inventory doesn't use the SpriteRenderer
            if (go.GetComponent <ItemData>() != null && go.GetComponent <SpriteRenderer>() != null)
            {
                // compare to the items in the itemData list that were sent from the server
                foreach (DataPacket item in itemData)
                {
                    // if the position and id are the same as item sent from database then duplicate, don't send back
                    if (item.x == go.transform.position.x && item.y == go.transform.position.y &&
                        item.itemNum == go.GetComponent <ItemData>().item.ID)
                    {
                        // set skip to true and break out of item comparison
                        skip = true;
                        break;
                    }
                }
                // if skip is true don't put in list for database, and check next gameobject
                if (skip)
                {
                    skip = false;
                    continue;
                }
                goList.Add(go);
                //Debug.Log ("putting in LIST: " + go.name);
            }
        }

        // for every item in the goList, get the item data and location
        foreach (GameObject go in goList)
        {
            ItemData idata = go.GetComponent <ItemData>();
            if (idata == null)
            {
                Debug.Log("ERROR!!! idata is null");
            }
            Debug.Log("item going to database: " + idata.item.Title);
            // create a new DataPacket with the item data
            DataPacket dp = new DataPacket((byte)idata.item.ID, go.transform.position.x, go.transform.position.y);
            // send the item data to the server
            DarkRiftAPI.SendMessageToServer(1, (ushort)clientID, dp);
        }

        // notes list filled as notes are written by function addNote, just send them to DB.
        foreach (DataPacket packet in notes)
        {
            Debug.Log("note going to database: " + packet.note);
            // temporarily sending the note packets as a string, for some reason won't send the DataPacket as a note
            // but can send DataPacket as a note from server to client
            DarkRiftAPI.SendMessageToServer(2, (ushort)clientID, packet.note + "|" + packet.x + "|" + packet.y);
        }

        // disconnect from server
        DarkRiftAPI.Disconnect();
    }