Code for updater

Vigintennalis Membrum
Vicennium
Joined
Aug 10, 2006
Messages
466
Reaction score
138
Public Class Form1
Dim oldresult


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


My.Computer.Network.DownloadFile("http://checkip.dyndns.org/", "C:\ip.txt", "", "", False, 100000, True)
TextBox1.Text = My.Computer.FileSystem.ReadAllText("C:\ip.txt")
Dim teststring = TextBox1.Text
Dim result
result = teststring.Substring(teststring.IndexOf(":") + 2)
teststring = Mid(result, 1, Len(result) - 16)
result = teststring
TextBox1.Text = result
If result <> oldresult Then


If My.Computer.FileSystem.DirectoryExists("C:\wwwroot\") = True Then
My.Computer.FileSystem.WriteAllText("C:\WWWRoot\ip.zuz", result, True)
Else
My.Computer.FileSystem.CreateDirectory("C:\wwwroot\")
My.Computer.FileSystem.WriteAllText("C:\WWWRoot\ip.zuz", result, True)
End If
Me.Text = result
oldresult = result
End If

End Sub
End Class


this is the code for a program to update the ip of the server (if dynamic) into the file called ip.zuz which will be held on the web server of the game server computer, the launcher i coded will download this file and extract the ip from the ip.zuz file and update the ip to be used for connecting to the server in the registry and ptreg.rgx file.
 
Last edited:
Incomplete and unreadable, as far as I can see. Also, not the solution I would choose.

There is no description of what sort of project this is, but I'm guess it is (for some reason) a WinForms project. However, we don't have the form to know what that should look like.

I guessed it should have a Timer object called Timer1, and a text box object called TextBox1.

I can write VB Code, and have built VB.net programs... I can't do anything with that code in that state. :(:

This would be more readable:-
Code:
[COLOR=Blue]Public Class[/COLOR] [COLOR=Teal]Form1[/COLOR]
    [COLOR=Blue]Dim[/COLOR] oldresult


    [COLOR=Blue]Private Sub[/COLOR] Form1_Load([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.[COLOR=Teal]Object[/COLOR], [COLOR=Blue]ByVal[/COLOR] e[COLOR=Blue] As[/COLOR] System.[COLOR=Teal]EventArgs[/COLOR]) [COLOR=Blue]Handles MyBase[/COLOR].Load


    [COLOR=Blue]End Sub[/COLOR]

    [COLOR=Blue]Private Sub[/COLOR] Timer1_Tick([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.Object, [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] Timer1.Tick


        [COLOR=Blue]My[/COLOR].Computer.Network.DownloadFile([COLOR=DarkRed]"[/COLOR][COLOR=DarkRed]http://checkip.dyndns.org/[/COLOR][COLOR=DarkRed]"[/COLOR], [COLOR=DarkRed]"C:\ip.txt"[/COLOR], [COLOR=DarkRed]""[/COLOR], [COLOR=DarkRed]""[/COLOR], [COLOR=Blue]False[/COLOR], 100000, [COLOR=Blue]True[/COLOR])
        TextBox1.Text = [COLOR=Blue]My[/COLOR].Computer.FileSystem.ReadAllText([COLOR=DarkRed]"C:\ip.txt"[/COLOR])
        [COLOR=Blue]Dim[/COLOR] teststring = TextBox1.Text
        [COLOR=Blue]Dim[/COLOR] result
        result = teststring.Substring(teststring.IndexOf([COLOR=DarkRed]":"[/COLOR]) + 2)
        teststring = Mid(result, 1, Len(result) - 16)
        result = teststring
        TextBox1.Text = result
        [COLOR=Blue]If[/COLOR] result <> oldresult [COLOR=Blue]Then[/COLOR]


            [COLOR=Blue]If My[/COLOR].Computer.FileSystem.DirectoryExists([COLOR=DarkRed]"C:\wwwroot\"[/COLOR]) = [COLOR=Blue]True Then[/COLOR]
                [COLOR=Blue]My[/COLOR].Computer.FileSystem.WriteAllText([COLOR=DarkRed]"C:\WWWRoot\ip.zuz"[/COLOR], result, [COLOR=Blue]True[/COLOR])
            [COLOR=Blue]Else[/COLOR]
                [COLOR=Blue]My[/COLOR].Computer.FileSystem.CreateDirectory([COLOR=DarkRed]"C:\wwwroot\"[/COLOR])
                [COLOR=Blue]My[/COLOR].Computer.FileSystem.WriteAllText([COLOR=DarkRed]"C:\WWWRoot\ip.zuz"[/COLOR], result, [COLOR=Blue]True[/COLOR])
            [COLOR=Blue]End If[/COLOR]
            [COLOR=Blue]Me[/COLOR].Text = result
            oldresult = result
        [COLOR=Blue]End If[/COLOR]

    [COLOR=Blue]End Sub[/COLOR]
[COLOR=Blue]End Class[/COLOR]
But it still won't compile as is.

Surely the "correct" (simplest) solution would be to perform DNS lookup on hostname and update hotuk.ini, or ptreg.rgx from the acquired result? Except that we should assume that users who play PT do not have the elevated administration access required to alter either of those files, or anything else in the PT installation outside the initial install time... at which point, this or similar code should either be part of the executable (ie, definitely not VB.net... or C# or Java, and probably not Python, Perl or PHP either) or should be part of a launcher which passes the IP as a parameter to a game.exe modified to accept one and connect to it.

I usually say don't do dynip, because the people who want to use dynamic IP most, are the ones who want to keep their dynamic IP embedded and encrypted in the executable so nobody can read it.

This whole topic is a can'o'worms IMHO. :lol: Never the less, good effort.
Rob say Code Monkey very diligent, but his output it stink.
His code not functional or elegant, what do Code Monkey think?
Code Monkey think maybe manager wanna write God damn login page himself?
Code Monkey not say it, out loud.
Code Monkey not crazy, just proud.
:wink:
 
Last edited:
its a server side update tool. it is to update the ip that the launcher connects to via web server. it is primarily for users who are running a server from a home machine with an adsl conenction where the ip changed frequently. i made it at university while my professor wasnt looking. didnt have time to make it at home so did it there. ill remake a revised version and upload the whole project.
 
Cool. While I was trying to build I wondered if this code ran as ASP.net and was meant to be embedded in a page... and that was why vb.net flipped me the bird. XD

I know nothing when it comes to ASP.net. :blush: But suspected it was supposed to be run server side.

I'd actually considered trying to get the code into the client to perform DNS lookup via Win32API. Many other games accept a domain name in their client config files, so it's a shame PT will only take an IP. Putting that in the launcher is easier, but having it in the client would be more elegant. ^_^ (maybe someday)
 
Try this.

Code:
    Private Sub UpdateIP()
        'Creates all variables
        Dim sReader As IO.StreamReader = Nothing
        Dim WebRequest As Net.WebRequest = Nothing
        Dim WebResponse As Net.WebResponse = Nothing

        Try

        WebRequest = Net.WebRequest.Create("http://checkip.dyndns.org/") 'Sets a request for IP page
        WebResponse = WebRequest.GetResponse 'Gets the response of the website
        sReader = New StreamReader(WebResponse.GetResponseStream) 'Assigns the response to a streamreader

        Dim IP_Regex As New System.Text.RegularExpressions.Regex("\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b") 'Finds the IP with a REGEX
        Dim IP As String = IP_Regex.Match(sReader.ReadToEnd).Value 'Gets the IP value

            If IO.Directory.Exists("C:\wwwroot") Then
                Dim sWriter As New IO.StreamWriter("C:\wwwroot\ip.zuz", False)
                sWriter.Write(IP)

                sWriter.Close()
                sWriter.Dispose()
            Else
                IO.Directory.CreateDirectory("C:\wwwroot")
                Dim sWriter As New IO.StreamWriter("C:\wwwroot\ip.zuz", False)
                sWriter.Write(IP)

                sWriter.Close()
                sWriter.Dispose()
            End If
        Catch ex As Exception
            MsgBox("Ooops... Something got wrong: " & ex.Message)
        Finally
            If Not sReader Is Nothing Then sReader.Close()
            If Not WebResponse Is Nothing Then WebResponse.Close()
        End Try
    End Sub
 
Crunch!
This:-
Code:
            If IO.Directory.Exists("C:\wwwroot") Then
                Dim sWriter As New IO.StreamWriter("C:\wwwroot\ip.zuz", False)
                sWriter.Write(IP)

                sWriter.Close()
                sWriter.Dispose()
            Else
                IO.Directory.CreateDirectory("C:\wwwroot")
                Dim sWriter As New IO.StreamWriter("C:\wwwroot\ip.zuz", False)
                sWriter.Write(IP)

                sWriter.Close()
                sWriter.Dispose()
            End If
Should read:-
Code:
            If IO.Directory.Exists("C:\wwwroot") Then
                Dim sWriter As New IO.StreamWriter("C:\wwwroot\ip.zuz", False)
            Else
                IO.Directory.CreateDirectory("C:\wwwroot")
                Dim sWriter As New IO.StreamWriter("C:\wwwroot\ip.zuz", False)
            End If
            sWriter.Write(IP)

            sWriter.Close()
            sWriter.Dispose()
Not sure how that is automatically getting the IP for the host domain name, but that's not saying it doesn't, simply that I can see wasted code even when I don't understand the code I'm looking at. :lol: Well done.

--- EDIT ---
Oh wait! No I see now, it's just using like a "what's my IP" and parsing the HTML returned as if it where a text file... That's okay then. :D:
 
Code:
Dns.GetHostAddresses(Environment.MachineName)
should do the trick... I think. (provided this service is on the same server as the PT server... if you are renting IIS webserver separate from your home PC running PT, then it would have to be run at home and upload to the IIS server)

In a launcher, you would probably want to Dns.GetHostAddress("dynip.org.myptdomain"), and write that out to the PT config. (without breaking UAC, and preferably working for non-"Power User" accounts)

Good call Vormav. :D:
 
Last edited:
that only gets the local ip of the machine. this code was written for vb.net using visual studio 2008. Ill make a release of the working program when i finish my launcher. Havent had a chance to work on it atm with getting my server going and uni work too :P

the purpose of this is primarily for those who are running small servers from small machines at home for their friends to play. This tool should run on the server machine, it will connect to the internet, pull the ip from that source, save it in a text file in the web server directory, the launcher(client side) can connect to this, and put the new ip in the ptreg.rgx file.
 
Yes, of course. I think we are looking for "a way" to do this, without being so strict on the method.

Why should the Launcher need to be fed this IP from the web-server? Are you preparing for DNS ban due to SOCA / PIPA? :lol:

We're also trying to avoid using a web site we don't run. Either from the Launcher or our own web-server. I think we'd rather not rely on checkip.dyndns.org, you know?

Are you saying the DNS.GetHostAddress() I suggest will give the LAN IP, not the WAN IP? If so, I'm still sure you could get it somehow. If you have registered a DynIP DNS then replacing Environment.MachineName with a string containing your registered Domain Name should work... Shouldn't it?

I'm still assuming that function is available in VB.net ASP. I know not all VB.net syntax works as ASP.
 
Last edited:
on further revision the best way to get your wan ip is going to be to connect to your isp then. the reason i used that website was for a quick fix for my updater. it can be applied to any website or server to obtain the ip. It was something i was working on whilst in university, covering the vs window with notepad every time lecturer walked by. As i say it was primarily a release for small servers for people who are on a dynamic ip and want to play with their friends. I will further revise it when i have a chance.



PS. its not asp. its a desktop application.
 
Oh okay... so, ASP / PHP or WHY is reading from the ip.zuz file to produce the web page? Sounds like another complexity I'd try to avoid, but it should work.

Easiest solution is to register a DynDNS name and have the client or launcher look up the IP for the domain name. Tried, tested, true and simplicity, even with Dynamic IP. (until SOCA or Chinese filters get involved)

If your server needs to know it's WAN IP... I'd probably still go for looking up a domain name.

But what is worse is that PT needs you to shut down change the configuration files and restart before it will acknowledge a changed IP. It's not a problem if your IP only changes when you are off-line, but that's not always the case. It's not a problem if you are small enough that your server isn't on 24/7 but, for example, my wife runs a WoW server which only she and I play, and it's still on 24/7. (we spend a lot of time living apart... and playing together :lol:)
 
its a vb.net forms application. It doesnt read from the ip.zuz file. it writes to it. it does this so that the launcher can find the file in the web server, download it, and get the correct server ip. If users are needing to automatically change the ip then i can write in a function to end the server.exe process and have the autorestarter restart the server with new ip values in the hotuk file. It was more of a basic program so that users could view it and change the code for themselves.
 
You could at least download the file to the temporary directory.

Environment.GetEnvironmentVariable("TEMP")

and wouldn't it be better to just resolve the dns:
Code:
    Public Function HostToStr(ByVal s As String) As String
        Dim hosts() As IPAddress = Dns.GetHostAddresses(s)

        If hosts.Length > 0 Then
            Return hosts(0).ToString()
        End If

        Return "0.0.0.0"
    End Function

    HostToStr("google.com")

God VB is and stays such an ugly language xD
 
Last edited:
VB Rocked before .net. XD

I think (though I don't understand why) gzuz thinks the server should not have a "domain name". So nothing to lookup in DNS. :(:

@gzuz: Yes, that was what I meant, your vb code writes the file, and your web server reads it back passing it to the launcher. Maybe you don't script the reading with anything. But still...
 
If you use dns, you can move the server to another datacenter without patching the client at all... You just have to update the dns and within 24 hours people will be connecting to the new server. If you don't want people looking up your private info at dns registrars whois info just use fake data; they don't care. Only some hosting companies care that you provide a valid id card...
 
Okay... I know gzuz answer to that is that he's thinking of small private servers. Maybe something run from home for a few close friends etc. Changing from one "Datacenter" on a dynamic IP to another will make no difference than your ISP changing the IP of the same "Datacenter". :wink:

OTOH, I've never filled in an id card to get a DynIP DNS entry. The whois info leads to the DNS host, and you get a free (maybe, check Ts'n'Cs) record on their Domain. So, for example, I may become bobsobol.dynamicipsrus.org, but the whois comes back to dynamiciprus.org.

Some example DynDNS providers:-
I'm sure you can find more. I've not checked them all out, some are only designed for "web" servers, and create a web-redirector page... that's no good, you need one that maps the DNS record to your IP. You run a little client on your server machine which either checks your WAN IP periodically and lets the DNS server know if it changes.

DNS entries are cached and distributed around the internet, so not everybody who looks up your IP from your domain name will go straight to the host you choose, and updates may not be "instant", or even the same for all users. (depends what DNS server they connect to) It's a bit like pop mail, the records just bounce around, every DNS server passes updates to every other DNS server it knows.
 
I wasn't talking about dyndns domains... For 10$ you have your personal domain for a year and you need to enter domain registrant information... Which doesn't matter.

To order dedicated servers nowadays you have to send a copy of "someone's" id card.

You are talking about homeservers and I was talking about dedicated servers located in data centers, that's why I got confused. xD

Of course there are free alternatives; I've totally forgot about those xD Then again you can still use the a No-IP domain which updates once every 5 minutes.

e.g. bobosobol.no-ip.org

The No-IP will always point to the correct dns record since the no-ip.org website won't change it's dns records. Just the subdomain records are changed, which are below the no-ip.org record. Thus the clients will ask the no-ip.org dns server which ip the subdomain points to.
 
Yea, well, I can't see where you would rent a datacenter with Dynamic IP.

Essentially though, I think we both agree that whatever you are doing a domain name is easier than looking up the IP for an unnamed server host and distributing that IP to clients via a page on the web server.

I'm not saying gzuz idea isn't cool, or wouldn't work... (clearly it does work) I'm just still not sure why you would choose to do it that way. What exactly is the advantage?
 
I never said anything about a datacenter and a dynamic ip. It is possible you want to upgrade or downgrade your server and then the ip will change. Which is only natural because you will get a new server.

Or you find a better and cheaper dedi server company and want to relocate the server. Or even move from your homeserver to a dedicated!! :p

Yeah, we definitely agree on that one @.@. A lot of official games out there use dns.

I am also wondering why anyone would do it like this, but ya it works so no one cares. It doesn't matter how you do it; if it works in the end, gz!!

Oh and bobsobol gz on Moderator rank ^_^ I didn't notice this earlier.
 
Back