Page 1 of 1

How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 5:24 pm
by Arantir
How to access to login database from gameserver?
Players have one account and they can play in few servers as in any other game, yes?
I have 2 gs and 1 ls. And also there are some things like Premium Account or some donate gold. And it should be related with whole account but not with some character.
Gameservers use different databases. So the most useful way is to save some special account`s data in loginserver`s database.
Aaand... The question is in thread name...
When I try to connect from gs, I get error like "gsDB.lsDB.accounts_data doesn`t exists" with qery like "SELECT * FROM lsDB.accounts_data ...". Scripts automatically put gameserver`s database`s name into a query. How to change this?

Re: How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 6:03 pm
by UnAfraid
Login Server have established connection with each Game Server you can use it to get what do you need.
Here's example Changeset 4917

Re: How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 6:37 pm
by Arantir
You means that I have to create own loginserverpacket?

Re: How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 6:52 pm
by Zoey76
Arantir wrote:You means that I have to create own loginserverpacket?
Both a sendable and a receivable packets.

Re: How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 7:10 pm
by Arantir
Not so easy that I hope. Will try to do it.
Thanks for the answer.

And may I ask (don`t want create new thread), is there some way to check the ping (in milliseconds) from gs to user?
For example user send ".ping" and see "Your ping is ~62 ms now". I thought about it, but don`t find a way.
In earlier client of game there was a column "ping" in server selection menu. So some way must exists...
You need to send a current time to user and get it back, after than compare old and current time to get the time which it takes to send packet forward and back. But I don`t know how to compel client return packet with time...

Re: How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 7:39 pm
by UnAfraid
Actually there's retail feature about that.
There's NetPing packets with known structure just nobody implemented that yet :)

Server sends a packet with 3 d's as far as i remember
first was some randomly generated key
second and third i don't remember, and client responds with another packet the id which server sent him.
So you record somewhere when you sent server packet and when did u received the packet from client
so Received Time - Sent Time = ping :)

Re: How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 8:59 pm
by Arantir
Yeah, now I know the name of this packet! =)
Found the packet structure in a gide for l2phx :mrgreen: :mrgreen:

Code: Select all

Server: Lenght 7 [NetPing]07 00        // length 7, constD9           // opcode D9, const99 BD 6A 0F  // some ping ID Client: Lenght 15 [NetPing]0F 00       // length 15, constB1          // opcode B1, const99 BD 6A 0F // some ping ID02 00 00 00 // const?00 10 00 00 // const?
maybe try to implement...

Re: How to access to login`s database from gameserver?

Posted: Fri Jul 06, 2012 9:44 pm
by jurchiks
other forks have been passing that NetPing code around for at least a year now, what do you mean - nobody implemented that yet?

Re: How to access to login`s database from gameserver?

Posted: Sat Jul 07, 2012 12:25 am
by UnAfraid
When i joined l2j community i shared the some implementation from a russian fork (Don't remember the name)

viewtopic.php?f=72&t=18046
UnAfraid wrote:It need's a big rework .. :)

Re: How to access to login`s database from gameserver?

Posted: Sat Jul 07, 2012 2:34 am
by Arantir
Hm... It was not hard to implement sending and receiving the packet... I already done it before saw your post.
What I have done:

Code: Select all

 // ***serverpacket***:public NetPing(L2PcInstance activeChar) {    // write current time    activeChar.setEXData("pingTime", System.currentTimeMillis()+"");    // EXData - my feature, some extra data for character - just an string array with 50 fields. very useful =)}protected void writeImpl() {    writeC(0xd9);    writeD(<some_id>); // i use constant =/} /// ***clienspacket***:protected void readImpl() {    some_id  = readD();    ping = readD(); // strange values returned 0_O... 5 msec one and 150 another time...                           // so I prefer to compare system time    readD();}protected void runImpl() {    L2PcInstance activeChar = getClient().getActiveChar();    if (activeChar == null) return;    long pingStart = Long.parseLong(activeChar.getEXData("pingTime"));    long ping = pingStart - System.currentTimeMillis();    activeChar.sendMessage("Your ping is ~"+ping +"msec.");    activeChar.setEXData("LatestPing", ping+"");} //*** handler ***/case 0xb1:    // NetPing    msg = new NetPing();    break; // ***some voiced***:if (command.equalsIgnoreCase("ping")){               activeChar.sendPacket(new NetPing(activeChar));} 
It is enough to get current ping =)

Re: How to access to login`s database from gameserver?

Posted: Sat Jul 07, 2012 9:14 am
by Arantir
About the login`s database...
I expected something like

Code: Select all

ResultSet data = getFromLogin("SELECT ...");
. But if it will be implemented by the packets then returned value will be in a different thread...
It means than I have to create one more packet for any single query to login database such as ChangePassword.
Is there more universal way to access login`s base?

Re: How to access to login`s database from gameserver?

Posted: Sat Jul 07, 2012 11:43 am
by tukune
:idea:

Code: Select all

Connection con = java.sql.DriverManager.getConnection("jdbc:mysql://192.168.0.100:3306/l2jls", "root", "open-sesame");PreparedStatement statement = con.prepareStatement("SELECT ...");ResultSet data = statement.executeQuery();

Re: How to access to login`s database from gameserver?

Posted: Sat Jul 07, 2012 11:49 am
by Arantir
:D exactly what i want!