Register for your free account! | Forgot your password?

You last visited: Today at 05:47

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# Proxy?

Discussion on C# Proxy? within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jun 2006
Posts: 965
Received Thanks: 576
C# Proxy?

Anyone have an example of a simple C# proxy? I can't get any sources I find online to work.
high6 is offline  
Thanks
2 Users
Old 10/24/2008, 08:56   #2
 
elite*gold: 0
Join Date: Apr 2006
Posts: 23
Received Thanks: 4
i know but a few people who could give you a working example, it's highly unlikley that they would however..
Leo_2 is offline  
Old 10/24/2008, 11:58   #3
 
elite*gold: 0
Join Date: Feb 2006
Posts: 550
Received Thanks: 82
No, make something your self instead of getting the hard part done for you.
ChingChong23 is offline  
Old 10/24/2008, 12:12   #4
 
MushyPeas's Avatar
 
elite*gold: 0
Join Date: Oct 2006
Posts: 800
Received Thanks: 89
Quote:
Originally Posted by high6 View Post
Anyone have an example of a simple C# proxy? I can't get any sources I find online to work.
/\
||
Not some noob, I suppose he means a basic generic proxy system for C#.
Otherwise I'd be quite surprised he's asking for a working co proxy source xD.
MushyPeas is offline  
Old 10/24/2008, 19:43   #5
 
elite*gold: 0
Join Date: Aug 2007
Posts: 295
Received Thanks: 89
@ChingChong23 Learn a little about the people you slag off before you post.

I beleive high6 is referring to either a general proxy source, or better: an outdated co proxy source, since other than the encryptions the method would still be the same.

/sorry for a kinda useless post, I didn't use c# although I did have a try I got rid of all my attempts (I'm useless with it)
Some-Guy is offline  
Old 10/24/2008, 22:04   #6
 
elite*gold: 0
Join Date: Jun 2006
Posts: 965
Received Thanks: 576
Sorry, I am asking for a general proxy.
high6 is offline  
Old 10/25/2008, 17:26   #7
 
unknownone's Avatar
 
elite*gold: 20
Join Date: Jun 2005
Posts: 1,013
Received Thanks: 381
I'm not gonna give you a full proxy, but here's a demonstration on how you might set up a basic proxy to listen on some ports, accept connectionson those ports, and handle events on those accepted connections. This uses a single thread for all connections.

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;


namespace CoProxyExample
{
    class CoProxy
    {
        private TcpListener m_authlistener;
        private TcpListener m_gamelistener;
        private ArrayList m_read_sock_set;
        private List<CoConnection> m_Connections;

        public CoProxy()
        {
            IPAddress localhost = IPAddress.Parse("127.0.0.1");
            m_authlistener = new TcpListener(localhost, 9958);
            m_gamelistener = new TcpListener(localhost, 5816);
            m_authlistener.Start();
            m_gamelistener.Start();

            m_read_sock_set = new ArrayList();
            m_read_sock_set.Add(m_authlistener.Server);
            m_read_sock_set.Add(m_gamelistener.Server);

            m_Connections = new List<CoConnection>();
        }
        public void RunProxy()
        {
            bool stopproxy = false;
            IPAddress loginserverIP = IPAddress.Parse("69.59.142.13");
            ArrayList tmp_sock_set = new ArrayList();
            while (true)
            {
                tmp_sock_set.Clear();
                tmp_sock_set = (ArrayList)m_read_sock_set.Clone();
                Socket.Select(tmp_sock_set, null, null, 1000);
                for (int i=0;i<tmp_sock_set.Count;i++)
                {
                    if (tmp_sock_set[i] == m_authlistener.Server)
                    {
                        Socket s1 = m_authlistener.AcceptSocket();
                        m_Connections.Add(new AuthConnection(s1));
                        m_Connections[m_Connections.Count - 1].ConnectToServer(loginserverIP, 9958);
                        m_read_sock_set.Add(s1);
                        m_read_sock_set.Add(m_Connections[m_Connections.Count-1].serversocket);
                    }
                    else if (tmp_sock_set[i] == m_gamelistener.Server)
                    {
                        Socket s2 = m_gamelistener.AcceptSocket();
                        m_read_sock_set.Add(s2);
                        m_Connections.Add(new GameConnection(s2));
                        m_read_sock_set.Add(m_Connections[m_Connections.Count - 1].serversocket);
                    }
                    else
                    {
                        FindConnection((Socket)tmp_sock_set[i]);
                    }
                }
                if (stopproxy)
                {
                    break;
                }
            }
            m_authlistener.Stop();
            m_maplistener.Stop();
        }

        private void FindConnection(Socket s)
        {
            for(int i=0;i<m_Connections.Count;i++)
            {
                if (m_Connections[i].IsPending(s)) break;
                if (m_Connections[i].IsDisconnected())
                {
                    m_read_sock_set.Remove(m_Connections[i].clientsocket);
                    m_read_sock_set.Remove(m_Connections[i].serversocket);
                    m_Connections.Remove(m_Connections[i]);
                    break;
                }
            }
        }
    }
}
The CoConnection is an abstract class which would contain the socket descriptor for the connection to the client and to the server, and would have the basic send/receive methods and IsPending() etc. You'd derive from this to contain the information specific to AuthConnection or GameConnection such as encryptions.

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using CoProxyExample.Packets;

namespace CoProxyExample
{
    abstract class CoConnection
    {

        private Socket m_clientConnection;
        private Socket m_serverConnection;
        private bool hasconnected;

        public CoConnection(Socket s)
        {
            m_clientConnection = s;
            m_serverConnection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            hasconnected = false;
        }

        public Socket clientsocket
        { 
            get { return m_clientConnection; }
        }

        public Socket serversocket
        {
            get { return m_serverConnection; }
        }

        public void ConnectToServer(IPAddress serverip, int port)
        {
            m_serverConnection.Connect(serverip, port);
            hasconnected = true;
        }

        public bool IsPending(Socket s)
        {
            if (m_clientConnection == s)
            {
                ReceiveFromClient();
                return true;
            }
            else if(m_serverConnection == s)
            {
                ReceiveFromServer();
                return true;
            }
            return false;
        }

        public bool IsDisconnected()
        {
            if (!hasconnected) return false;
            if (!m_clientConnection.Connected)
            {
                m_serverConnection.Disconnect(false);
                return true;
            }
            if (!m_serverConnection.Connected)
            {
                m_clientConnection.Disconnect(false);
                return true;
            }
            return false;
        }

        private void ReceiveFromClient()
        {
            Packet packet = new Packet(2048);
            int bsize = 0;
            bsize = m_clientConnection.Receive(packet.Buffer);
            if (bsize == 0)
            {
                m_clientConnection.Disconnect(false);
                return;
            }
            HandlePacketFromClient(packet);
        }

        private void ReceiveFromServer()
        {
            Packet packet = new Packet(2048);
            int bsize = 0;
            bsize = m_serverConnection.Receive(packet.Buffer);
            if (bsize == 0)
            {
                m_serverConnection.Disconnect(false);
                return;
            }
            HandlePacketFromServer(packet);
        }

        private void SendToServer(Packet packet)
        {
            m_serverConnection.Send(packet.Buffer, packet.Size, SocketFlags.None);
        }

        private void SendToClient(Packet packet)
        {
            m_clientConnection.Send(packet.Buffer, packet.Size, SocketFlags.None);
        }
    }
}
unknownone is offline  
Thanks
4 Users
Old 10/25/2008, 17:40   #8
 
elite*gold: 0
Join Date: Jun 2006
Posts: 965
Received Thanks: 576
Thanks,

Can you listen to a whole port with a proxy though? The sources I have seen use TcpListener.Bind() to bind to a port and capture/direct all traffic on that port. Never works for me though.

I will try what you have though, thanks again .
high6 is offline  
Old 10/25/2008, 18:02   #9
 
unknownone's Avatar
 
elite*gold: 20
Join Date: Jun 2005
Posts: 1,013
Received Thanks: 381
These do listen on a particular port. The TcpListener class has a few different constructors for that. The constructor I've used automatically calls Bind() with the arguments passed to it, so it's the same thing.
Binding doesn't capture all traffic on a port, it waits for new connections to it, which is when you Accept() the connections, give each new connection a descriptor and then listen for data on those.
unknownone is offline  
Old 10/26/2008, 02:21   #10
 
elite*gold: 0
Join Date: Jun 2006
Posts: 965
Received Thanks: 576
Quote:
Originally Posted by unknownone View Post
These do listen on a particular port. The TcpListener class has a few different constructors for that. The constructor I've used automatically calls Bind() with the arguments passed to it, so it's the same thing.
Binding doesn't capture all traffic on a port, it waits for new connections to it, which is when you Accept() the connections, give each new connection a descriptor and then listen for data on those.
So with the port binded you have to direct the traffic right?
high6 is offline  
Old 11/01/2008, 10:40   #11
 
iliveoncaffiene's Avatar
 
elite*gold: 0
Join Date: Oct 2005
Posts: 332
Received Thanks: 69
Port binding means that you have a process or listener attached to a port.
Only 1 process may listen on a port at a time, so binding to a port basically "latches" the process onto the port for listening.

After that it doesn't "direct" the traffic, it receives all of the incoming data.
The proxy forwards the data from the server to the client and from the client to the server, acting as a "middle-man" between the client and the server.
iliveoncaffiene is offline  
Old 11/03/2008, 04:05   #12
 
elite*gold: 0
Join Date: Jun 2006
Posts: 965
Received Thanks: 576
Quote:
Originally Posted by iliveoncaffiene View Post
Port binding means that you have a process or listener attached to a port.
Only 1 process may listen on a port at a time, so binding to a port basically "latches" the process onto the port for listening.

After that it doesn't "direct" the traffic, it receives all of the incoming data.
The proxy forwards the data from the server to the client and from the client to the server, acting as a "middle-man" between the client and the server.
Well either way, none of the examples work for me.
high6 is offline  
Old 11/12/2008, 22:14   #13
 
elite*gold: 0
Join Date: Jun 2007
Posts: 30
Received Thanks: 1
Quote:
Originally Posted by high6 View Post
Well either way, none of the examples work for me.
could ya show what you tried so I know what not to do.
Sk1nny is offline  
Old 11/13/2008, 15:07   #14
 
elite*gold: 0
Join Date: Jun 2006
Posts: 965
Received Thanks: 576
I used everything he showed except select cause I don't really understand it.
high6 is offline  
Old 12/31/2008, 13:05   #15
 
elite*gold: 0
Join Date: Dec 2008
Posts: 2
Received Thanks: 0
thnxxxxxxxxxxxxxxxxxxxx
scorpion1900 is offline  
Reply


Similar Threads Similar Threads
[How To] Proxy use/ Proxy Lists (~10k)!!!
08/26/2010 - Tutorials - 3 Replies
hey Com, ich wurde letztens gefragt ob ich ein paar proxys habe und wie er sie benutzen kann. Ok, dachte ich mir machs public: Was braucht ihr? -Proxifier -Proxies
Proxy geht nicht/Proxy doesn´t work
08/10/2010 - Metin2 Private Server - 0 Replies
Folgendes Problem: Squid ist installiert. Startet anscheinend nicht richtig, funktioniert einfach nicht. Die Meldung welche kommt, wenn man startet: 2010/08/10 17:02:26| Starting Squid Cache version 2.7.STABLE9 for i386-portbld-freebsd7.1... 2010/08/10 17:02:26| Process ID 1952 2010/08/10 17:02:26| With 11095 file descriptors available 2010/08/10 17:02:26| Using kqueue for the IO loop
Wer will ne Proxy ? Ja genau du willst ne Proxy xD !
07/23/2010 - Metin2 Private Server - 11 Replies
Moin, Wer hat einen Root-Server und will eine Proxy ? Proxy: Proxy ermöglicht dir deine IP zu ändern die dan auch die selbe bleibt. Dadurch hast du auf einem DynDNS oder Root-Server 24/7 GM-Rechte..... Ich hab nen Install script das ich den auch Pub machen werde Aber davor testen möchte.
4326 PROXY FIX Post All Proxy Fixes Here
11/26/2006 - CO2 Exploits, Hacks & Tools - 22 Replies
post only the fixes for proxy here plz dont post original file. NO QUESTIONS PLZ. DONT ASK FOR ORIGINAL QOPROXY. just search and hope u dont get the keylogged version :P Fix for patch4326 (not really an intentional patch for proxy. required little editing ;)) replace old ini in qoproxy folder with this one



All times are GMT +1. The time now is 05:47.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.