Ejemplo n.º 1
0
        public void mListenDispatchTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            object[] incomingClients = null;
            if (mIncomingClients.Count > 0)
            {
                lock (mIncomingClients)
                {
                    incomingClients = mIncomingClients.ToArray();
                    mIncomingClients.Clear();
                }
            }

            if (incomingClients != null)
            {
                foreach (Socket client in incomingClients)
                {
                    NetServiceConnection cc = new NetServiceConnection(client);
                    mClientConnections.Add(cc);
                    if (mConnectedDelegates != null)
                    {
                        mConnectedDelegates(cc);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //??
        Stream WriteConnectCommand(string debuggerAddress, Int32 debuggerPort, string clientName)
        {
            try
            {
                Stream       stream = new MemoryStream();
                BinaryWriter writer = NetServiceConnection.GetBinaryWriter(stream);

                CTSPacketHeader header = new CTSPacketHeader(writer, (byte)ServiceListPacketTypes.cCommand);

                writer.Write((int)ListCommands.cConnect);
                writer.Write(clientName);
                writer.Write(debuggerAddress);
                writer.Write(debuggerPort);

                //-- get the size
                header.writeSize(writer);

                return(stream);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }
Ejemplo n.º 3
0
 public void ReadData(NetServiceConnection clientConnection, byte type, BinaryReader reader)
 {
     if (type == (byte)ServiceListPacketTypes.cServiceList)
     {
         ReadServiceList(reader);
     }
 }
Ejemplo n.º 4
0
        public NetServiceListClient(string hostIP, int hostPort)
        {
            mListServerConnection = new NetServiceConnection(hostIP, hostPort);
            mHostIP = hostIP;

            mListServerConnection.mReadDelegates         += new NetServiceConnection.ReadDelegate(ReadData);
            mListServerConnection.mDisconnectedDelegates += new NetServiceConnection.DisconnectedDelegate(OnClientDisconnected);
            mListServerConnection.startRead();

            mListServerConnection.write(WriteListCommand());
        }
Ejemplo n.º 5
0
        public void OnNewClientConnection(NetServiceConnection clientConnection)
        {
            mAllClients.Add(clientConnection);

            mActiveClient = clientConnection;

            // a New client has arrived, hook up the delagates.
            mActiveClient.mReadDelegates         += new NetServiceConnection.ReadDelegate(readData);
            mActiveClient.mDisconnectedDelegates += new NetServiceConnection.DisconnectedDelegate(OnClientDisconnected);
            mActiveClient.startRead();

            //ConnectDebugger(0);
        }
Ejemplo n.º 6
0
        public void OnClientDisconnected(NetServiceConnection clientConnection)
        {
            //mGamesListWindow.listBox1.Items.Remove(clientConnection.mConnectionName);
            ////-- If we get down to zero, reEnabled the listbox.
            //if (mGamesListWindow.listBox1.Items.Count <= 0)
            //{
            //   mGamesListWindow.sessionReset();
            //}
            //since everything uses client 0 we must clear the list so that the next valid connection will be client 0 again
            mConnectedClients.Clear();
            mDebuggerClients.Clear();

            //this.Text = "RemoteGameDebugger: Disconnected";
        }
Ejemplo n.º 7
0
        public void OnNewDebuggerClientConnection(NetServiceConnection clientConnection)
        {
            mAllClients.Add(clientConnection);

            mActiveClient = clientConnection;
            mDebuggerClients.Add(clientConnection);

            // a New client has arrived, hook up the delagates.
            mActiveClient.mReadDelegates         += new NetServiceConnection.ReadDelegate(readData);
            mActiveClient.mDisconnectedDelegates += new NetServiceConnection.DisconnectedDelegate(OnClientDisconnected);
            mActiveClient.startRead();

            if (DebuggerConnected != null)
            {
                DebuggerConnected.Invoke(mActiveClient);
            }
        }
Ejemplo n.º 8
0
        public void DebuggerDisconnect(int clientID)
        {
            if (mDebuggerClients.Count <= clientID)
            {
                return;
            }

            ////-- send disconnect packet to game.
            MemoryStream         memStream = new MemoryStream();
            DettachDebugger      setBP     = new DettachDebugger(memStream);
            NetServiceConnection client    = mDebuggerClients[clientID];

            client.write(memStream);

            ////-- reEnable the listbox.
            //sessionReset();
        }
Ejemplo n.º 9
0
        // write
        public DettachDebugger(Stream stream)
        {
            try
            {
                //BinaryWriter writer = new BinaryWriter(stream, System.Text.Encoding.Unicode);
                BinaryWriter writer = NetServiceConnection.GetBinaryWriter(stream);


                CTSPacketHeader header = new CTSPacketHeader(writer, (byte)GameAppDebuggerPacketTypes.cDebuggerDettach);

                //-- get the size
                header.writeSize(writer);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 10
0
        ///////////////////////////////////////////////////

        public void ConnectDebugger(int clientID)
        {
            if (mConnectedClients.Count <= clientID)
            {
                return;
            }
            NetServiceConnection client = mConnectedClients[clientID];

            //-- tell game we want to attach.
            MemoryStream memStream = new MemoryStream();

            // Determine the IPAddress of this machine
            string strHostName = "";

            // NOTE: DNS lookups are nice and all but quite time consuming.
            strHostName = Dns.GetHostName();
            IPHostEntry    ipEntry = Dns.GetHostByName(strHostName);
            DebuggerAttach toGame  = new DebuggerAttach(memStream, ipEntry.AddressList[0].ToString(), 1339, client.mClientName);

            client.write(memStream);
        }
Ejemplo n.º 11
0
        // read
        //public void ParseServiceCommand(BinaryReader reader)
        //{
        //   try
        //   {
        //      ListCommands command = (ListCommands)reader.ReadInt32();

        //      if (command == ListCommands.cConnect)
        //      {


        //         //mClientName = reader.ReadString();
        //         //mDebuggerAddress = reader.ReadString();
        //         //mDebuggerPort = reader.ReadInt32();
        //      }
        //   }
        //   catch (Exception e)
        //   {
        //      Console.WriteLine(e.ToString());
        //   }
        //}

        Stream WriteListCommand()
        {
            try
            {
                Stream       stream = new MemoryStream();
                BinaryWriter writer = NetServiceConnection.GetBinaryWriter(stream);

                CTSPacketHeader header = new CTSPacketHeader(writer, (byte)ServiceListPacketTypes.cCommand);

                writer.Write((int)ListCommands.cGetList);

                //-- get the size
                header.writeSize(writer);
                return(stream);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }
Ejemplo n.º 12
0
        public void readData(NetServiceConnection clientConnection, byte type, BinaryReader reader)
        {
            if (mbAttached == true)
            {
                return;
            }
            reader = NetServiceConnection.GetBinaryReader(reader.BaseStream);

            if (type == (byte)GameAppDebuggerPacketTypes.cDebuggerDettach)
            {
                //-- game has gone away, dettach thyself.
                sessionReset();
            }
            else if (type == (byte)GameAppDebuggerPacketTypes.cAdvertiseGame)
            {
                AdvertiseGame p = new AdvertiseGame(reader);
                String        s = p.mGameName;

                if (p.mAdvertise == true)
                {
                    clientConnection.mClientName = s.Replace(":0", "");
//               clientConnection.mClientName = p.mGameName;  //was this a fix or an old bug?
                    //mGamesListWindow.listBox1.Items.Add(clientConnection.mConnectionName);
                    mConnectedClients.Add(clientConnection);
                    //if (mGamesListWindow.listBox1.Items.Count == 1)
                    //{
                    //   mGamesListWindow.listBox1.SelectedIndex = 0;
                    //}
                    mbAttached = true;

                    ConnectDebugger(0);
                }

                //int index = mGamesListWindow.listBox1.FindStringExact(p.mGameName);
                ////-- didn't find game, add it.
                //if (index == ListBox.NoMatches)
                //{
                //   if (p.mAdvertise == true)
                //   {
                //      clientConnection.mConnectionName = p.mGameName;
                //      mGamesListWindow.listBox1.Items.Add(clientConnection.mConnectionName);
                //      mConnectedClients.Add(clientConnection);
                //      if (mGamesListWindow.listBox1.Items.Count == 1)
                //      {
                //         mGamesListWindow.listBox1.SelectedIndex = 0;
                //      }
                //   }
                //}
                //else
                //{
                //   //-- we found a match. remove if advert is false
                //   if (p.mAdvertise == false)
                //   {
                //      mGamesListWindow.listBox1.Items.RemoveAt(index);
                //   }
                //}
            }
            else
            {
                byte[] bytes = reader.ReadBytes(100);

                //MessageBox.Show(this, "bad packet");
            }
        }
Ejemplo n.º 13
0
 public void OnClientDisconnected(NetServiceConnection clientConnection)
 {
 }