public void SendDataToServer(byte[] data)
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteBytes(data);
     network.myStream.Write(buffer.ToArray(), 0, buffer.ToArray().Length);
     buffer = null;
 }
 public void SendCancelMatch()
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteInteger(4);
     SendDataToServer(buffer.ToArray());
     buffer = null;
 }
    public void SendAccount()
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteInteger(1);

        if (_username.text == string.Empty)
        {
            Debug.Log("Please insert a username.");
            return;
        }

        if (_password.text == string.Empty)
        {
            Debug.Log("Please insert a password.");
            return;
        }

        if (_password2.text != _password.text)
        {
            Debug.Log("Your password do not match.");
            return;
        }

        buffer.WriteString(_username.text);
        buffer.WriteString(_password.text);

        SendDataToServer(buffer.ToArray());
        buffer = null;
    }
    void HandlePlayerData(byte[] data)
    {
        int packetnum;

        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteBytes(data);
        packetnum = buffer.ReadInteger();

        int i = buffer.ReadInteger();

        if (Globals.instance.MyIndex < 1)
        {
            Globals.instance.MyIndex       = i;
            ClientSendData.instance._index = Globals.instance.MyIndex;
        }

        _LoginWindow.SetActive(false);


        Network.instanceP[i].index = i;
        General.instance.SetPlayerX(i, buffer.ReadFloat());
        General.instance.SetPlayerY(i, buffer.ReadFloat());
        General.instance.SetPlayerZ(i, buffer.ReadFloat());

        Network.instanceP[i].Username = buffer.ReadString();

        _playerPrefs = Instantiate(_playerPrefs, new Vector3(General.instance.GetPlayerX(i), General.instance.GetPlayerY(i), General.instance.GetPlayerZ(i)), Quaternion.identity);
        _playerPrefs.GetComponent <NetPlayer>().Index = i;
        _playerPrefs.name = "Player " + i + " : " + Network.instanceP[i].Username;
    }
Beispiel #5
0
        void HandleLogin(int index, byte[] data)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteBytes(data);

            int    packetnum = buffer.ReadInteger();
            string username  = buffer.ReadString();
            string password  = buffer.ReadString();

            if (!Globals.database.AccountExists(index, username))
            {
                //SendUserDoesNotExist
                return;
            }
            if (!Globals.database.PasswordOK(index, username, password))
            {
                // Send password not correct
                return;
            }
            Console.WriteLine("Player" + username + " logged in successfully!");
            //Send Player into game
            //Load player
            Globals.database.LoadPlayer(index, username);
            Globals.tempPlayer[index].inGame = true;
            // Set tempPlayer.ingame = true;
            Globals.networkSendData.SendInGame(index);
        }
Beispiel #6
0
 public void SendDataTo(int index, byte[] data)
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteBytes(data);
     Network.Clients[index].myStream.BeginWrite(buffer.ToArray(), 0, buffer.ToArray().Length, null, null);
     buffer = null;
 }
Beispiel #7
0
 public void SendRefreshBar(int index)
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteInteger(4);
     buffer.WriteInteger(Network.TempPlayer[index].Castbar);
     SendDataTo(index, buffer.ToArray());
     buffer = null;
 }
Beispiel #8
0
        public void SendAlertMsg(int index, string alertMsg)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteInteger((int)Enumerations.ServerPackets.SAlertMsg);
            buffer.WriteString(alertMsg);

            SendDataTo(index, buffer.ToArray());
        }
Beispiel #9
0
 public  void SendDisconnect(int index,int connected)
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteInteger((int)Enumerations.ServerPackets.SPlayerDisconnect);
     buffer.WriteInteger(connected);
     buffer.WriteInteger(index);
     SendDataToAll(buffer.ToArray());
 }
Beispiel #10
0
        void HandleLookingForMatch(int index, byte[] Data)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteBytes(Data);
            int packet = buffer.ReadInteger();

            RoomInstance.instance.JoinOrCreateRoom(index);
        }
 public void SendDisconnect()
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteInteger((int)Enumerations.ClientPackets.CHandleDisconnect);
     buffer.WriteInteger(_index);
     buffer.WriteInteger(_connected);
     SendDataToServer(buffer.ToArray());
     buffer = null;
 }
 public void SendLogin()
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteInteger((int)Enumerations.ClientPackets.CHandleLogin);
     buffer.WriteString(_loginUser.text);
     buffer.WriteString(_loginPass.text);
     SendDataToServer(buffer.ToArray());
     buffer = null;
 }
 public void SendNewAccount()
 {
     KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
     buffer.WriteInteger((int)Enumerations.ClientPackets.CNewAccount);
     buffer.WriteString(_username.text);
     buffer.WriteString(_password.text);
     SendDataToServer(buffer.ToArray());
     buffer = null;
 }
Beispiel #14
0
        public void SendAlertMsg(int index, string alertMsg)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();

            buffer.WriteInteger(1);
            buffer.WriteString(alertMsg);

            SendDataTo(index, buffer.ToArray());
        }
Beispiel #15
0
    void HandleRageBar(int packetNum, byte[] data)
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteBytes(data);
        int packet  = buffer.ReadInteger();
        int ragebar = buffer.ReadInteger();

        _rage.text          = ragebar.ToString();
        _ragebar.fillAmount = (float)(decimal)ragebar / 10;
    }
    public void SendLookingForMatch()
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteInteger(3);
        SendDataToServer(buffer.ToArray());
        LFG.SetActive(true);
        inMenu.SetActive(false);

        buffer = null;
    }
        void HandleNewAccount(int index, byte[] data)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteBytes(data);
            int    packetNum = buffer.ReadInteger();
            string username  = buffer.ReadString();
            string password  = buffer.ReadString();

            Globals.database.AddAccount(username, password);
        }
    public void SendLogin()
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();

        buffer.WriteInteger(2);
        buffer.WriteString(_loginUser.text);
        buffer.WriteString(_loginPass.text);

        SendDataToServer(buffer.ToArray());
        buffer = null;
    }
    public void SendNewAccount()
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();

        buffer.WriteInteger(1);
        buffer.WriteString(_username.text);
        buffer.WriteString(_password.text);

        SendDataToServer(buffer.ToArray());
        buffer = null;
    }
    void HandleAlertMsg(int packetNum, byte[] data)
    {
        int packetnum;

        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteBytes(data);
        packetnum = buffer.ReadInteger();

        string AlertMsg = buffer.ReadString();

        Debug.Log(AlertMsg);
    }
Beispiel #21
0
        public void SendMatchMaking(int room)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteInteger(3);
            buffer.WriteString(Network.Player[RoomInstance._room[room].player[0]].Username);
            buffer.WriteString(Network.Player[RoomInstance._room[room].player[1]].Username);
            SendDataToRoom(room, buffer.ToArray());
            buffer = null;

            Network.TempPlayer[RoomInstance._room[room].player[0]].inMatch = true;
            Network.TempPlayer[RoomInstance._room[room].player[1]].inMatch = true;
        }
Beispiel #22
0
        void HandleDisconnect(int index, byte[] data)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteBytes(data);
            int packetnum = buffer.ReadInteger();

            int connected = buffer.ReadInteger();
            int Index     = buffer.ReadInteger();

            Globals.tempPlayer[index].inGame = false;
            // Set tempPlayer.ingame = true;
            Globals.networkSendData.SendDisconnect(Index, connected);
        }
Beispiel #23
0
    public void HandleData(byte[] data)
    {
        int packetnum;

        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteBytes(data);
        packetnum = buffer.ReadInteger();
        buffer    = null;
        if (packetnum == 0)
        {
            return;
        }

        HandleMessages(packetnum, data);
    }
Beispiel #24
0
        public void SendIngame(int index)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteInteger(1);

            //Player Data
            buffer.WriteString(Network.Player[index].Username);
            buffer.WriteString(Network.Player[index].Password);
            buffer.WriteInteger(Network.Player[index].Level);
            buffer.WriteByte(Network.Player[index].Access);
            buffer.WriteByte(Network.Player[index].FirstTime);

            SendDataTo(index, buffer.ToArray());
            buffer = null;
        }
Beispiel #25
0
    void HandleIngame(int packetNum, byte[] data)
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteBytes(data);

        int packetnum = buffer.ReadInteger();

        Player.instance.Username  = buffer.ReadString();
        Player.instance.Password  = buffer.ReadString();
        Player.instance.Level     = buffer.ReadInteger();
        Player.instance.Access    = buffer.ReadByte();
        Player.instance.FirstTime = buffer.ReadByte();
        buffer = null;

        _playerWelcome.text        = "Welcome back, " + Player.instance.Username;
        MenuManager.instance._menu = MenuManager.Menu.Ingame;
    }
Beispiel #26
0
        public byte[] PlayerData(int index)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();

            // prevent out of bounds
            if (index > Constants.MAX_PLAYERS)
                return null;

            buffer.WriteInteger((int)Enumerations.ServerPackets.SPlayerData);
            buffer.WriteInteger(index);
            buffer.WriteFloat(Globals.general.GetPlayerX(index));
            buffer.WriteFloat(Globals.general.GetPlayerY(index));
            buffer.WriteFloat(Globals.general.GetPlayerZ(index));

            buffer.WriteString(Globals.player[index].Username);
            return buffer.ToArray();
        }
Beispiel #27
0
    void HandleMatchMaking(int packetNum, byte[] data)
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteBytes(data);
        int    packet  = buffer.ReadInteger();
        string player1 = buffer.ReadString();
        string player2 = buffer.ReadString();

        if (player1 == Player.instance.Username)
        {
            _opponent.text = player2;
        }
        else
        {
            _opponent.text = player1;
        }

        MenuManager.instance._menu = MenuManager.Menu.InMatch;
    }
    public void SendMovement(float x, float y, float z, float rotX, float rotY, float rotZ, float rotW)
    {
        KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
        buffer.WriteInteger((int)Enumerations.ClientPackets.CHandleMovement);

        // Send position and rotation

        buffer.WriteFloat(x);
        buffer.WriteFloat(y);
        buffer.WriteFloat(z);

        buffer.WriteFloat(rotX);
        buffer.WriteFloat(rotY);
        buffer.WriteFloat(rotZ);
        buffer.WriteFloat(rotW);

        SendDataToServer(buffer.ToArray());
        buffer = null;
    }
Beispiel #29
0
        public void HandleData(int index, byte[] data)
        {
            int     packetnum;
            Packet_ Packet;

            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteBytes(data);
            packetnum = buffer.ReadInteger();
            buffer    = null;
            if (packetnum == 0)
            {
                return;
            }

            if (Packets.TryGetValue(packetnum, out Packet))
            {
                Packet.Invoke(index, data);
            }
        }
Beispiel #30
0
        void HandleNewAccount(int index, byte[] Data)
        {
            KaymakGames.KaymakGames buffer = new KaymakGames.KaymakGames();
            buffer.WriteBytes(Data);
            int    packet   = buffer.ReadInteger();
            string username = buffer.ReadString();
            string password = buffer.ReadString();

            if (Database.instance.AccountExist(username) == true)
            {
                //SendAlertMsg
                return;
            }


            Database.instance.AddAccount(index, username, password);

            ServerSendData.instance.SendIngame(index);
        }