Ive been creating a Auto Patch system in C#

Where if people connect to the server they get the latest patches if they dont have it. but ive got a program when auto patching only auto patches latest patch can anyone help me with this problem its meant to get all patches what haven't been downloaded.

Script

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;


public class ThreadedTcpSrvr
{
//server post to Liston to.
const int listenPort = 9528;


private TcpListener client;


public ThreadedTcpSrvr()
{
client = new TcpListener(IPAddress.Any, listenPort);
client.Start();
Console.WriteLine("Waiting for clients on port " + listenPort);
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);


//current latest patch
const string clientVer = "1004";
string msgUpdate = "UPDATE";
string msgReady = "READY";
//ip
string msgIP = "58.54.48.123";
//where to get file
string msgLocation = "/enzf/1004.exe";


while (true)
{
try
{
data = new byte[1024];
recv = ns.Read(data, 0, data.Length);
string message = Encoding.ASCII.GetString(data).Substring(0, clientVer.Length);


switch (message)
{
case clientVer:
data = Encoding.ASCII.GetBytes(msgReady);
ns.Write(data, 0, data.Length);
goto done;
default:
data = Encoding.ASCII.GetBytes(msgUpdate + " " + msgIP + " " + msgLocation);
ns.Write(data, 0, data.Length);
goto done;
}


}
catch
{
break;
}
}
done:
connections--;
Console.WriteLine("Client {0}:{1} disconnected: {2} active connection(s)", IPAddress.Parse(((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString()), ((IPEndPoint)client.Client.RemoteEndPoint).Port.ToString(), connections);
ns.Close();
client.Close();
}
}

//////////

How do i get it to get earler patches.
E.G. im set as patch 1000 and current patch is 1004. how do i get it to download patch 1001,1002,1003 and 1004

Please help me. And sorry if this is in the wrong section.

Edited 3 Years Ago by happygeek: fixed formatting

Well your server version is clearly 1004, if your client says its 1000, then either you do the annoying online game style where you downloaded 1001, and restart, and then get 1002, and restart, etc..
or
you keep a record of which files changed in which patches and for all the files that changed in patches greater than the current file number, send patches.

Well your server version is clearly 1004, if your client says its 1000, then either you do the annoying online game style where you downloaded 1001, and restart, and then get 1002, and restart, etc..
or
you keep a record of which files changed in which patches and for all the files that changed in patches greater than the current file number, send patches.

Can you help me do the annoying online game style please.
what am i missing

The server would have to send to the client the next version up from the one it has, so it needs to keep a history of the versions that have been before, and send the appropriate "patch"

The server would have to send to the client the next version up from the one it has, so it needs to keep a history of the versions that have been before, and send the appropriate "patch"

how i do that

I feel I am repeating myself, the server would need to have a history...

i understand what u mean but how would i add it?

Um, if you got as far as writing a patching system, you should be able to work out how to add a list of previous version numbers and when someone attaches send them the next one down the list.. Id be surprised

Um, if you got as far as writing a patching system, you should be able to work out how to add a list of previous version numbers and when someone attaches send them the next one down the list.. Id be surprised

can u show me an example please

untested, so

int curpos = versions.IndexOf(ClientVer);
if (curpos == -1)
{
   // version  unknown
}
else
{
  if (curpos<versions.Count-1)
  {
    // send curpos+1 version
  }
  else
  {
    // version is current
  }
}

Im surprised something that simple needed such explaination.

This article has been dead for over six months. Start a new discussion instead.