Arcturus-Community/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java

162 lines
5.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.messages.rcon;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo;
2018-11-17 14:28:00 +01:00
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.outgoing.users.MeMenuSettingsComposer;
2018-10-07 00:28:00 +02:00
import com.eu.habbo.messages.outgoing.users.UpdateUserLookComposer;
2018-07-06 15:30:00 +02:00
import com.google.gson.Gson;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class UpdateUser extends RCONMessage<UpdateUser.JSON>
{
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public UpdateUser()
{
super(UpdateUser.JSON.class);
}
@Override
public void handle(Gson gson, JSON json)
{
if (json.user_id > 0)
{
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(json.user_id);
if (habbo != null)
{
habbo.getHabboStats().addAchievementScore(json.achievement_score);
if (json.block_following != -1)
{
habbo.getHabboStats().blockFollowing = json.block_following == 1;
}
if (json.block_friendrequests != -1)
{
habbo.getHabboStats().blockFriendRequests = json.block_friendrequests == 1;
}
if (json.block_roominvites != -1)
{
habbo.getHabboStats().blockRoomInvites = json.block_roominvites == 1;
}
if (json.old_chat != -1)
{
habbo.getHabboStats().preferOldChat = json.old_chat == 1;
}
if (json.block_camera_follow != -1)
{
habbo.getHabboStats().blockCameraFollow = json.block_camera_follow == 1;
}
2018-10-07 00:28:00 +02:00
if (!json.look.isEmpty())
{
habbo.getHabboInfo().setLook(json.look);
2018-11-17 14:28:00 +01:00
habbo.getHabboInfo().getCurrentRoom().sendComposer(new UpdateUserLookComposer(habbo).compose());
2018-10-07 00:28:00 +02:00
if (habbo.getHabboInfo().getCurrentRoom() != null)
{
2018-11-17 14:28:00 +01:00
habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserDataComposer(habbo).compose());
2018-10-07 00:28:00 +02:00
}
}
2018-09-28 21:25:00 +02:00
habbo.getHabboStats().run();
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new MeMenuSettingsComposer(habbo));
}
else
{
2018-10-07 00:28:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection())
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
try (PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET achievement_score = achievement_score + ? " +
(json.block_following != -1 ? ", block_following = ?" : "") +
(json.block_friendrequests != -1 ? ", block_friendrequests = ?" : "") +
(json.block_roominvites != -1 ? ", block_roominvites = ?" : "") +
(json.old_chat != -1 ? ", old_chat = ?" : "") +
(json.block_camera_follow != -1 ? ", block_camera_follow = ?" : "") +
" WHERE user_id = ? LIMIT 1"))
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
int index = 1;
statement.setInt(index, json.achievement_score);
2018-07-06 15:30:00 +02:00
index++;
2018-10-07 00:28:00 +02:00
if (json.block_following != -1)
{
statement.setString(index, json.block_following == 1 ? "1" : "0");
index++;
}
if (json.block_friendrequests != -1)
{
statement.setString(index, json.block_friendrequests == 1 ? "1" : "0");
index++;
}
if (json.block_roominvites != -1)
{
statement.setString(index, json.block_roominvites == 1 ? "1" : "0");
index++;
}
if (json.old_chat != -1)
{
statement.setString(index, json.old_chat == 1 ? "1" : "0");
index++;
}
if (json.block_camera_follow != -1)
{
statement.setString(index, json.block_camera_follow == 1 ? "1" : "0");
index++;
}
statement.setInt(index, json.user_id);
statement.execute();
2018-07-06 15:30:00 +02:00
}
2018-10-07 00:28:00 +02:00
if (!json.look.isEmpty())
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
try (PreparedStatement statement = connection.prepareStatement("UPDATE users SET look = ? WHERE id = ? LIMIT 1"))
{
statement.setString(1, json.look);
statement.setInt(2, json.user_id);
statement.execute();
}
2018-07-06 15:30:00 +02:00
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
}
}
2018-10-07 00:28:00 +02:00
public static class JSON
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public int user_id;
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public int achievement_score = 0;
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public int block_following = -1;
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public int block_friendrequests = -1;
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public int block_roominvites = -1;
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public int old_chat = -1;
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
public int block_camera_follow = -1;
2018-10-07 00:28:00 +02:00
public String look = "";
2018-07-06 15:30:00 +02:00
//More could be added in the future.
}
}