[Guide] Autopatch server explained

09/01/2008 20:16 MushyPeas#1
If for some reason you want to set up your own autopatch server to go with your private conquer server, the following info should be all you need to get you going.

Update: Included an example of a working, but by no means complete autopatch server C# script, you can download it from the attachment, it's merely a demonstration to get you started.


[Client - Server communication]

All you need is a simple tcp/ip connection to the autopatch server.
(TQ's official server: 69.59.148.97 on port 9528)

Client already up to date
Code:
Client: 5057
Server: READY
So if you code your own autopatch server you will have to check the client's version against the latest version and if he's up to date all you have to send back is "READY".

Client not up to date?
Code:
Client: 5056
Server: UPDATE 64.151.87.40 enzf/5057.exe
If he's not up to date you send back "UPDATE 64.151.87.40 enzf/5057.exe" which consist of:
- The Red part is the text "UPDATE".
- The Green part is the IP address of the server where you host your updates / patches, so this is NOT the same as your autopatch server IP unless you also host the actual patch files on that machine.
- The Blue part is the folder and file name of the update / patch.


[Editing SocketConfig.ini]

After you set up your own autopatch server (you have all the info you need now) make sure you edit your \AutoPatch\SocketConfig.ini and possibly autopatch.dat (not sure if this is even used) to point to your server instead of TQ's.

The important part in the default file looks like this (it points to tq's servers)

Quote:
[Server]
count=3
Server1=U1 69.59.148.97 9528 69.59.148.97 9528
Server2=U2 69.59.146.45 9528 69.59.146.45 9528
Server3=U3 121.207.249.53 9528 121.207.249.53 9528
Since we want to put in our own server we have to replace it with our own IP (66.666.66.666 in this example) and autopatch server port (9528 in this example) like this.

Quote:
[Server]
count=1
Server1=U1 66.666.66.666 9528 66.666.66.666 9528

[Optional: Editing config.ini]

Additionally you can also edit \AutoPatch\config.ini so that in case your Auto update server is down for some reason, players can still click the "manual" button to go to your own patch download webpage.

Edit this to your own webpage
Quote:
manualupdate = http://co.91.com/downloads/patch.shtml

If you have any questions, feel free to ask, but preferably only after you have actually read and tried what's in my post already.
09/03/2008 15:28 YukiXian#2
Nice, But.. I don't really Understand what to do, .. .May you can better explain that?
09/03/2008 15:48 MushyPeas#3
Quote:
Originally Posted by YukiXian View Post
Nice, But.. I don't really Understand what to do, .. .May you can better explain that?
Have a look at this tutorial with example code (In C# since I assume that's what you're used to).
[Only registered and activated users can see links. Click Here To Register...]

You can practically just copy that code and read the short accompanying text, it will take a little bit of effort but it'll leave you with a good insight into how servers work :)

Once you have this code in your project you should be able to fit in the few packets I posted earlier with ease, good luck.

Edit: Also found a possibly easier to use code base.
Code:
/*
C# Network Programming 
by Richard Blum

Publisher: Sybex 
ISBN: 0782141765
*/
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

public class ThreadedTcpSrvr {
   private TcpListener client;

   public ThreadedTcpSrvr()
   {
      client = new TcpListener(9050);
      client.Start();

      Console.WriteLine("Waiting for clients...");
      while(true)
      {
         while (!client.Pending())
         {
            Thread.Sleep(1000);
         }

         ConnectionThread newconnection = new ConnectionThread();
         newconnection.threadListener = this.client;
         Thread newthread = new Thread(new
                   ThreadStart(newconnection.HandleConnection));
         newthread.Start();
      }
   }

   public static void Main()
   {
      ThreadedTcpSrvr server = new ThreadedTcpSrvr();
   }
}

class ConnectionThread
{
   public TcpListener threadListener;
   private static int connections = 0;

   public void HandleConnection()
   {
      int recv;
      byte[] data = new byte[1024];

      TcpClient client = threadListener.AcceptTcpClient();
      NetworkStream ns = client.GetStream();
      connections++;
      Console.WriteLine("New client accepted: {0} active connections",
                        connections);

      string welcome = "Welcome to my test server";
      data = Encoding.ASCII.GetBytes(welcome);
      ns.Write(data, 0, data.Length);

      while(true)
      {
         data = new byte[1024];
         recv = ns.Read(data, 0, data.Length);
         if (recv == 0)
            break;
      
         ns.Write(data, 0, recv);
      }
      ns.Close();
      client.Close();
      connections--;
      Console.WriteLine("Client disconnected: {0} active connections",
                         connections);
   }
}
09/04/2008 01:16 MushyPeas#4
Update: Included an example of a working, but by no means complete autopatch server C# script, you can download it from [Only registered and activated users can see links. Click Here To Register...], it's merely a demonstration to get you started.
09/04/2008 01:25 nTL3fTy#5
Quote:
Originally Posted by MushyPeas View Post
manualupdate = [Only registered and activated users can see links. Click Here To Register...] is what you should edit to match your own
It auto-parsed the link.. :(

Spiffy guide.
09/04/2008 01:31 MushyPeas#6
Quote:
Originally Posted by nTL3fTy View Post
It auto-parsed the link.. :(

Spiffy guide.
Fixed that too :p
Should be all set now! *crosses fingers*
09/04/2008 14:22 YukiXian#7
Were to player you AutoPatchServ file? And how I can see its working?
09/04/2008 15:14 MushyPeas#8
Quote:
Originally Posted by YukiXian View Post
Were to player you AutoPatchServ file? And how I can see its working?
Make a new C# > Windows > Console Application project and put it in there.
09/04/2008 16:18 YukiXian#9
Can u also make it with an Windows Form Application? Would be alot easyr...
09/04/2008 17:39 MushyPeas#10
Quote:
Originally Posted by YukiXian View Post
Can u also make it with an Windows Form Application? Would be alot easyr...
I don't really see the added value plus this is only a proof of concept to show everyone how it works, I'll leave it up to others to tinker with as they want.
09/04/2008 17:42 ~Yuki~#11
Form is better i think :P
09/04/2008 17:51 MushyPeas#12
Quote:
Originally Posted by lolmaster123 View Post
Form is better i think :P
What superior functionality does a form offer?
09/04/2008 21:24 YukiXian#13
Quote:
Originally Posted by MushyPeas View Post
I don't really see the added value plus this is only a proof of concept to show everyone how it works, I'll leave it up to others to tinker with as they want.

Well, I won't get ur Autopatcher work, I changed the port to my port and Ip to my Ip, I can't run my server and that programm at the same time, ...
09/04/2008 22:49 MushyPeas#14
Quote:
Originally Posted by YukiXian View Post
Well, I won't get ur Autopatcher work, I changed the port to my port and Ip to my Ip, I can't run my server and that programm at the same time, ...
Then don't use the same port for 2 seperate programs.. that's just asking for problems.
The whole reason ports (plural) even exist is to allow us to have more than a single connection to a remote application at a time, so if you want to run 2 servers (game server + autopatch server) you are going to have to use 2 ports.
09/05/2008 12:52 YukiXian#15
Quote:
Originally Posted by MushyPeas View Post
Then don't use the same port for 2 seperate programs.. that's just asking for problems.
The whole reason ports (plural) even exist is to allow us to have more than a single connection to a remote application at a time, so if you want to run 2 servers (game server + autopatch server) you are going to have to use 2 ports.
Explain me that 2 ports, And.. I mean with the Form Application, When you Start your Private Server client, It will open the Autopatcher, Patch it and close. After closing the Client will be started...

You know how to make that?