Page 1 of 2

Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 10:43 am
by morozaw
If you want to receive support we need this info to help you properly.
» Find Revision
L2J Revision Number: newest / all
L2JDP Revision Number: newest /all

Hello guys, i'm looking for from about 3 hours a solution for this problem.
How i can connect to my server on dynamic ip without editing l2.ini?
Editing and patching system is the only best way or did You have better solution of this problem? I know - client mods are prohibited on this forum.
Client H5 - server l2j newest.
I've find in web some scripts / program to automatic editing hosts file but of course links are dead.

Any other ideas?

My server dns:
morozaw.dyndns.org

Cheers!

Re: Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 11:23 am
by BiggBoss
inject connect function to redirect the host. Any socket based app will go througt this function

Re: Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 11:29 am
by morozaw
Could You write a short tutorial what do You mean or give link to smth? :)
Did You mean shortcut with added comand in line with hostname?

Re: Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 1:42 pm
by tukune
:!:

Code: Select all

@ECHO OFFSET YOURHOST=morozaw.dyndns.orgSET AUTHHOST=l2authd.lineage2.com TITLE %YOURHOST%perl -e "use Socket;print """127.0.0.1 localhost\r\n$ip %AUTHHOST%\r\n""" if $ip=join('.',unpack C4=>(gethostbyname '%YOURHOST%')[4]);exit not $ip;">hosts.txt||(ECHO Error: %YOURHOST% - Cannot Resolve IP Address.& PAUSE & GOTO :EOF)COPY hosts.txt %SystemRoot%\system32\drivers\etc\hostsCD /D "%ProgramFiles%\NCZ0ft\Lineage II\system"CD /D "%ProgramFiles(x86)%\NCZ0ft\Lineage II\system"START L2.bin

Re: Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 1:42 pm
by BiggBoss

Re: Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 2:56 pm
by morozaw
Thank You for reply.
BiggBoss, it is not my level of programming yet.
I thought it is something more simple. Maybe somewhere is a complete app?

JOJO, this script editing host file?
As I conjecture, I must have perl binaries installed in Windows?
Sorry for stupid question - how to run it?
Somewhere i see this code in batch script.Unfortunately, this script is not universal.
Script works only with English version of system. I must edit it every time, when player has other default language in system.

Something else? :)
I think, this will be helpfull not only for me :)

Re: Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 6:08 pm
by UnAfraid
perl?

that's simple bat scripting

Re: Best way to connect with server on dynamic IP.

Posted: Sun Sep 15, 2013 6:15 pm
by jurchiks
JOJO's code clearly says "perl -e"...

Re: Best way to connect with server on dynamic IP.

Posted: Mon Sep 16, 2013 9:15 am
by morozaw
Guys, maybe somebody would like to help?
Jurchiks, thanks! :)

Re: Best way to connect with server on dynamic IP.

Posted: Mon Sep 16, 2013 10:10 am
by UnAfraid
I'd rather code some launcher on C#

Re: Best way to connect with server on dynamic IP.

Posted: Mon Sep 16, 2013 10:20 am
by jurchiks
You need to maintain the connection throughout the game session (we're talking about dynamic IP here), can a launcher do that?

Re: Best way to connect with server on dynamic IP.

Posted: Mon Sep 16, 2013 10:49 am
by BiggBoss
[c] #include <windows.h>#include <winsock2.h>#include <stdlib.h> #pragma comment(lib,"ws2_32.lib"); typedef int (__stdcall* new_connect)(SOCKET socket, sockaddr *name, int namelen);new_connect hook; int __stdcall InjectedConnect(SOCKET socket, sockaddr *name, int namelen) {    sockaddr_in * name_in = (sockaddr_in*)name;    name_in->sin_addr->S_un.S_addr = inet_addr("your.hostname.goes.here");        return hook(socket,name,namelen);} void inject() {    char * alloc_mem = (char*)VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE);        HMODULE ws2_32 = GetModuleHandle(L"ws2_32.dll");    if(ws2_32 == 0) {        ws2_32 = LoadLibrary(L"ws2_32.dll");    }        char * old_connect_addr = (char*)GetProcAddress(ws2_32, "connect");        if(*old_connect_addr == 0xe9) {        int old_relative = *(int*)(old_connect_addr + 1);        DWORD32 absolute = (DWORD32)(old_connect_addr + old_relative + 5);        *alloc_mem = 0xe9;        *(int*)(alloc_mem + 1) = (int)(absolute - (alloc_mem + 5));    } else {        memcpy(alloc_mem,old_connect_addr,5);        *(alloc_mem + 5)= 0xe9;        *(int*)(alloc_mem + 6) = (int)(old_connect_addr + 5 - (alloc_mem + 10));    }        DWORD prot;    VirtualProtect(old_connect_addr,5,PAGE_EXECUTE_READWRITE, &prot);    *old_connect_addr = 0xe9;    *(int*)(old_connect_addr + 1) = (int)( &InjectedConnect - (old_connect_addr + 5));    VirtualProtect(old_connect_addr,5,prot,&prot);        hook = (new_connect)alloc_mem;} _declspec(dllexport) BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {    if(ul_reason_for_call == DLL_PROCESS_ATTACH || ul_reason_for_call == DLL_THREAD_ATTACH)        inject();    return TRUE;} [/c]

Re: Best way to connect with server on dynamic IP.

Posted: Mon Sep 16, 2013 11:00 am
by UnAfraid
jurchiks wrote:You need to maintain the connection throughout the game session (we're talking about dynamic IP here), can a launcher do that?
Yes why not?

Re: Best way to connect with server on dynamic IP.

Posted: Mon Sep 16, 2013 11:12 am
by morozaw
Many many thanks BiggBoss.
I think You should sticky this code for other users if it works :)

Could You tell me in short how it works and how to compile it?
I must inject this into running program? How to make it automatically?
Sorry, i am newbie in this :)

UnAfraid, what about the launcher?
Maybe this is good base for that?

Cheers!

Re: Best way to connect with server on dynamic IP.

Posted: Mon Sep 16, 2013 11:51 am
by BiggBoss
compile to a dll. Now, you have 2 ways, attach it to the l2 executable header or create a remote thread in the l2 process, thats all.