示例#1
0
        private void InitiliazeClients()
        {
            GameClients = new Client[BaseInformationReader.Max_Players];

            for (int i = 1; i < BaseInformationReader.Max_Players; i++)
            {
                GameClients[i] = new Client();
            }

            m_UnityServer.AppendNewLog("All Clients have been setup correctly!");
        }
示例#2
0
        public void HandleData(byte[] data, int client)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            m_PacketID    = buffer.ReadInteger();
            m_ClientToken = buffer.ReadInteger();

            buffer = null;

            if (m_PacketID == 0)
            {
                m_UnityServer.AppendNewLog("A bad package was send from client: " + m_ClientToken);
                return;
            }
            PacketHandler(m_ClientToken, m_PacketID, data);
        }
示例#3
0
 //TODO: Check if unique client token exists in database :)
 private void ProccessLogin(int LoginToken, int ClientID)
 {
     m_UnityServer.AppendNewLog("ClientID: " + m_ClientID + "|| Unique token: " + m_LoginToken);
     for (int i = 1; i < BaseInformationReader.Max_Players; i++)
     {
         if (i == ClientID)
         {
             m_LocalDatabase.InitliazeLocalDataContainer(m_LoginToken, ClientID);
             SendReturnPackageToClient(ClientID, LoginToken);
         }
     }
 }
示例#4
0
        /// <summary>
        /// Send a data to a specific client.
        /// </summary>
        public void SendTo(int client_Index, byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);

            if (m_BaseNetwork.GameClients[client_Index].Client_Socket != null)
            {
                m_BaseNetwork.GameClients[client_Index].Client_Stream.BeginWrite(buffer.ToArray(), 0, buffer.ToArray().Length, null, null);
            }
            else
            {
                m_UnityServer.AppendNewLog("Something went wrong when sending a packet to client: " + client_Index);
            }

            buffer = null;
        }
示例#5
0
        /// <summary>
        /// Initliaze the game server - By button
        /// </summary>
        public void InitiliazeServer()
        {
            m_UnityServer = UnityServer.Instance;

            m_ServerListener = new TcpListener(IPAddress.Parse(BaseInformationReader.IpAdress), BaseInformationReader.Server_Port);
            m_ServerListener.Start();
            m_ServerListener.BeginAcceptTcpClient(OnAcceptNewClient, null);

            m_NetworkReceiver = new NetworkReceiver(this);
            NetworkSend       = new NetworkSender(this);

            MySQL = new MySql();
            MySQL.MySQLInit();
            m_UnityServer.AppendNewLog("The server has been initiliazed succesfully" + BaseInformationReader.Server_Port);

            InitiliazeClients();
        }