mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Added packet for sending credit updates
This commit is contained in:
parent
4979c8438a
commit
75f1e092d5
1 changed files with 45 additions and 0 deletions
|
|
@ -1,12 +1,16 @@
|
|||
package ms.net.event;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Locale;
|
||||
|
||||
import ms.Management;
|
||||
import ms.net.IoReadEvent;
|
||||
import ms.net.IoSession;
|
||||
import ms.net.packet.IoBuffer;
|
||||
import ms.system.mysql.SQLManager;
|
||||
import ms.system.util.ManagementConstants;
|
||||
import ms.world.PlayerSession;
|
||||
import ms.world.WorldDatabase;
|
||||
|
|
@ -73,6 +77,47 @@ public final class HSReadEvent extends IoReadEvent {
|
|||
player.getWorld().getPlayers().remove(username);
|
||||
player.setWorldId(0);
|
||||
break;
|
||||
case 36:
|
||||
buf = new IoBuffer();
|
||||
username = ByteBufferUtils.getString(buffer).toLowerCase();
|
||||
password = ByteBufferUtils.getString(buffer);
|
||||
int credits = buffer.getInt();
|
||||
if (!password.equals(ManagementConstants.getSECRET_KEY())){
|
||||
System.out.println("Password mismatch (attempt=" + password + ")!");
|
||||
buf.put(1);
|
||||
buff = buf.toByteBuffer();
|
||||
buff.flip();
|
||||
session.queue(buff);
|
||||
return;
|
||||
}
|
||||
try (Connection con = SQLManager.getConnection()) {
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT credits FROM members WHERE username = \"" + username + "\";");
|
||||
int original;
|
||||
if (rs.next()) original = rs.getInt(1);
|
||||
else {
|
||||
buf.put(2);
|
||||
buff = buf.toByteBuffer();
|
||||
buff.flip();
|
||||
session.queue(buff);
|
||||
return;
|
||||
}
|
||||
stmt.execute("UPDATE members SET credits = " + (original + credits) + " WHERE username = \"" + username + "\";");
|
||||
buf.put(0);
|
||||
buf.putInt(original + credits);
|
||||
buff = buf.toByteBuffer();
|
||||
buff.flip();
|
||||
session.queue(buff);
|
||||
} catch (Exception e) {
|
||||
buf.put(3);
|
||||
buf.putString(e.toString());
|
||||
buff = buf.toByteBuffer();
|
||||
buff.flip();
|
||||
session.queue(buff);
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
System.err.println("Unhandled handshake opcode: " + opcode + ".");
|
||||
session.disconnect();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue