diff --git a/src/main/java/com/alterdekim/game/component/GameServer.java b/src/main/java/com/alterdekim/game/component/GameServer.java index c9dd169..b39fb07 100644 --- a/src/main/java/com/alterdekim/game/component/GameServer.java +++ b/src/main/java/com/alterdekim/game/component/GameServer.java @@ -57,7 +57,7 @@ public class GameServer { @Autowired private GoodsService goodsService; - private final Map players; + private final Map players; private final ObjectMapper xmlMapper; @@ -66,7 +66,7 @@ public class GameServer { this.xmlMapper = new XmlMapper().registerModule(new JavaTimeModule()); } - public void onConnect(long playerId, String hwId, ConnectedProcessor connectedProcessor) { + public void onConnect(int playerId, String hwId, ConnectedProcessor connectedProcessor) { log.warn("GameServer.onConnect() connect: {}", playerId); Optional username = users.getUsernameById(playerId); if( username.isEmpty() || !AuthenticationUtil.hwIdAuth(users.findByUsername(username.get()), hwId) || this.players.containsKey(playerId) ) { @@ -76,7 +76,7 @@ public class GameServer { this.players.put(playerId, new Player(connectedProcessor, username.get())); } - public void onMessage(long playerId, List params ) { + public void onMessage(int playerId, List params ) { try { log.info("GameServer.onMessage() pid: {}, params: {}", playerId, params); switch(CommandType.fromString( (String) params.get(0).getValue() )) { @@ -100,7 +100,7 @@ public class GameServer { } } - private void setPlayerAvatarPosition(long playerId, SetPlayerAvatarPosition message) { + private void setPlayerAvatarPosition(int playerId, SetPlayerAvatarPosition message) { if( message.getCoordinates() != null ) { players.get(playerId).setX((Double) message.getCoordinates().get("x").getValue()); players.get(playerId).setY((Double) message.getCoordinates().get("y").getValue()); @@ -114,14 +114,14 @@ public class GameServer { ); } - private void setPlayerAvatarState(long playerId, SetPlayerAvatarState message) { + private void setPlayerAvatarState(int playerId, SetPlayerAvatarState message) { players.get(playerId).setState(message.getState()); this.sendInPlayersLocation(playerId, CommandType.SetUserAvatarState, new SetPlayerState(playerId, message.getState()) ); } - private void processUserMessage(long playerId, UserMessage message) throws JsonProcessingException { + private void processUserMessage(int playerId, UserMessage message) throws JsonProcessingException { log.info("GameServer.processUserMessage() message: {}", message); switch (UserCommandType.fromString(message.getCommandType())) { case GetUserInitData -> { @@ -131,8 +131,8 @@ public class GameServer { case UserFriendsGet, GetOnlineUserFriends -> this.sendResult(playerId, message.getTransactionId(), users.getFriendsOfUser(playerId, players)); case UserFriendsRequests -> this.sendResult(playerId, message.getTransactionId(), users.getRequestsOfUser(playerId, players)); case RevokeUserFriendship -> { - users.removeFriendshipWithUser(playerId, Long.parseLong((String) message.getArguments().get(0).getValue())); - this.call(Long.parseLong((String) message.getArguments().get(0).getValue()), CommandType.OnFriendsRemoved, playerId); + users.removeFriendshipWithUser(playerId, Integer.parseInt((String) message.getArguments().get(0).getValue())); + this.call(Integer.parseInt((String) message.getArguments().get(0).getValue()), CommandType.OnFriendsRemoved, playerId); } case ApplyUserFriendship -> this.applyUserFriendship(playerId, (String) message.getArguments().get(0).getValue(), (String) message.getArguments().get(1).getValue()); case GetClubMap -> // todo: implement @@ -152,7 +152,9 @@ public class GameServer { } long requestedLocation = ((Number) message.getArguments().get(1).getValue()).longValue(); if( requestedLocation == -1L ) { - this.sendResult(playerId, message.getTransactionId(), xmlMapper.writeValueAsString(locationService.getHomeByUserId(playerId))); + int homePlayerId = Integer.parseInt((String) message.getArguments().get(0).getValue()); + this.players.get(playerId).setHomeId(homePlayerId); + this.sendResult(playerId, message.getTransactionId(), xmlMapper.writeValueAsString(locationService.getHomeByUserId(homePlayerId))); return; } if( requestedLocation == -2L ) { @@ -184,14 +186,14 @@ public class GameServer { ); this.users.setWeaponsCount(playerId, this.users.getIntegerUserProperty(playerId, PlayerProperties.WeaponsCount, 15) - 1); } - case GetUserInfo -> getUserInfo(playerId, ((Double) message.getArguments().get(0).getValue()).longValue(), message); + case GetUserInfo -> getUserInfo(playerId, ((Double) message.getArguments().get(0).getValue()).intValue(), message); case GetUserAvatar -> getAvatar(playerId, message); case SaveUserAvatarChanges -> saveAvatar(playerId, message); case GetUserUnlocks -> this.sendResult(playerId, message.getTransactionId(), "123"); case GetSnInvitePanelData -> {} case GetGrantBlocks -> {} case UseMagicAbility -> this.sendInPlayersLocation(playerId, CommandType.UseMagicAbility, new UseMagicAbility( - Long.parseLong((String) message.getArguments().get(0).getValue()), + Integer.parseInt((String) message.getArguments().get(0).getValue()), ((Double) message.getArguments().get(1).getValue()).intValue() )); case SetDefaultUserPhone -> { @@ -203,7 +205,7 @@ public class GameServer { this.users.setDefaultBackground(playerId, bgId); } case QueryUserFriendship -> { - long participantId = ((Double) message.getArguments().get(0).getValue()).longValue(); + int participantId = ((Double) message.getArguments().get(0).getValue()).intValue(); relationshipService.sendRequest(playerId, participantId); this.call(participantId, CommandType.OnFriendshipRequestAdded, new OneFR( @@ -216,7 +218,7 @@ public class GameServer { this.sendResult(playerId, message.getTransactionId(), balance); } case PhoneMessage -> { - long receiverId = message.getArguments().get(0).getType() == AMFValueType.NUMBER ? ((Double) message.getArguments().get(0).getValue()).longValue() : Long.parseLong((String) message.getArguments().get(0).getValue()); + int receiverId = message.getArguments().get(0).getType() == AMFValueType.NUMBER ? ((Double) message.getArguments().get(0).getValue()).intValue() : Integer.parseInt((String) message.getArguments().get(0).getValue()); if (receiverId <= 0) return; String messageText = ((String) message.getArguments().get(1).getValue()); PhoneMessage pm = new PhoneMessage(); @@ -239,7 +241,7 @@ public class GameServer { } case CardMessage -> { if( !subtractUsualTickets(playerId, 20) ) return; - long receiverId = ((Number) message.getArguments().get(0).getValue()).longValue(); + int receiverId = ((Number) message.getArguments().get(0).getValue()).intValue(); int postcardId = ((Number) message.getArguments().get(1).getValue()).intValue(); Postcard postcard = new Postcard(); postcard.setIsNew(true); @@ -264,7 +266,7 @@ public class GameServer { } } - private void lockSomething(long playerId, int what2Lock, Boolean state, UserMessage message) { + private void lockSomething(int playerId, int what2Lock, Boolean state, UserMessage message) { if( what2Lock == -2 ) { this.users.pushUserProperty(playerId, PlayerProperties.IsClubLocked, state); } else { @@ -273,12 +275,12 @@ public class GameServer { this.sendResult(playerId, message.getTransactionId(), state); } - private void buySomething(long playerId, AMFObject obj, UserMessage message) { + private void buySomething(int playerId, AMFObject obj, UserMessage message) { List array = (List) obj.getValue(); array.forEach(i -> this.buyOne(playerId, i, message)); } - private void buyOne(long playerId, AMFObject item, UserMessage message) { + private void buyOne(int playerId, AMFObject item, UserMessage message) { Map obj = (Map) item.getValue(); long goodId = Long.parseLong((String) obj.get("GoodId").getValue()); boolean isMagic = ((Number) obj.get("Currency").getValue()).longValue() == 2; @@ -306,7 +308,7 @@ public class GameServer { this.sendResult(playerId, message.getTransactionId(), new BuyGoodResultGood(true, new ArrayList<>())); } - private boolean subtractUsualTickets(long userId, int amount) { + private boolean subtractUsualTickets(int userId, int amount) { int val = this.users.getUsualTickets(userId); if ( val >= amount ) { val -= amount; @@ -317,7 +319,7 @@ public class GameServer { return false; } - private boolean subtractMagicTickets(long userId, int amount) { + private boolean subtractMagicTickets(int userId, int amount) { int val = this.users.getMagicTickets(userId); if ( val >= amount ) { val -= amount; @@ -328,14 +330,14 @@ public class GameServer { return false; } - private void applyUserFriendship(Long userId, String acceptString, String denyString) { - List accepted = Arrays.stream(acceptString.split(",")) + private void applyUserFriendship(Integer userId, String acceptString, String denyString) { + List accepted = Arrays.stream(acceptString.split(",")) .filter(s -> !s.isEmpty()) - .map(Long::parseLong) + .map(Integer::parseInt) .collect(Collectors.toList()); - List denied = Arrays.stream(denyString.split(",")) + List denied = Arrays.stream(denyString.split(",")) .filter(s -> !s.isEmpty()) - .map(Long::parseLong) + .map(Integer::parseInt) .collect(Collectors.toList()); users.acceptFriendshipWithUsers(userId, accepted); users.denyFriendshipsWithUsers(userId, denied); @@ -344,7 +346,7 @@ public class GameServer { accepted.forEach(uid -> this.call(uid, CommandType.OnFriendsAdded, m)); } - private void saveAvatar(long playerId, UserMessage message) { + private void saveAvatar(int playerId, UserMessage message) { Map changes = (Map) message.getArguments().get(0).getValue(); List bodyParts = (List) changes.get("BodyParts").getValue(); @@ -369,22 +371,21 @@ public class GameServer { this.updateLocationPlayers(playerId, this.players.get(playerId).getLocationId()); } - private void getAvatar(long playerId, UserMessage message) throws JsonProcessingException { + private void getAvatar(int playerId, UserMessage message) throws JsonProcessingException { String r = xmlMapper.writeValueAsString(users.getUserAvatarByUserId(playerId)); r = r.substring(13); r = r.substring(0, r.length() - 14); - log.info("getAvatar: {}", r); this.sendResult(playerId, message.getTransactionId(), r); } - private void getUserInfo(long playerId, long targetId, UserMessage message) throws JsonProcessingException { + private void getUserInfo(int playerId, int targetId, UserMessage message) throws JsonProcessingException { String r = xmlMapper.writeValueAsString(new GetUserInfo(users.getUserInfoByUserId(targetId, false, playerId), users.getOtherUserAvatar(targetId))); r = r.substring(11); r = r.substring(0, r.length()-12); this.sendResult(playerId, message.getTransactionId(), r); } - private void setPlayerLocation(long playerId, SetLocationMessage message) { + private void setPlayerLocation(int playerId, SetLocationMessage message) { Player p = this.players.get(playerId); this.deleteSelf(playerId, p.getLocationId()); int prevLocation = p.getLocationId(); @@ -392,23 +393,22 @@ public class GameServer { p.setX((Double) message.getCoordinates().get("x").getValue()); p.setY((Double) message.getCoordinates().get("y").getValue()); p.setState(message.getStartState()); - log.info("updateLocationPlayers: {} => {}", prevLocation, p.getLocationId()); this.updateLocationPlayers(playerId, prevLocation); this.sendResult(playerId, message.getTransactionId(), ""); } - private void deleteSelf(long playerId, int locationId) { - this.sendInLocation(locationId, CommandType.RemoveUserFromLocation, playerId); + private void deleteSelf(int playerId, int locationId) { + Player p = this.players.get(playerId); + this.sendInLocation(locationId, p.getHomeId(), CommandType.RemoveUserFromLocation, playerId); } - private void updateLocationPlayers(long playerId, int prevLocation) { + private void updateLocationPlayers(int playerId, int prevLocation) { int locationId = this.players.get(playerId).getLocationId(); - log.info("removeUserFromLocation {}", locationId); - this.sendInLocation(prevLocation, CommandType.RemoveUserFromLocation, playerId); + long homeId = this.players.get(playerId).getHomeId(); + this.sendInLocation(prevLocation, homeId, CommandType.RemoveUserFromLocation, playerId); for( int i = 0; i < 3; i++ ) { try { Thread.sleep(300); - log.info("addUserToLocation1"); this.sendInPlayersLocation(playerId, CommandType.AddUserToLocation, new AddUserToLocation( playerId, users.getAvatarById(playerId, this.players.get(playerId)) @@ -420,7 +420,7 @@ public class GameServer { this.players.keySet().forEach(pid -> { Player p = this.players.get(pid); if( p.getLocationId() != locationId ) return; - log.info("addUserToLocation2"); + if( p.getLocationId() == -1 && p.getHomeId() != homeId ) return; this.call(playerId, CommandType.AddUserToLocation, new AddUserToLocation( pid, users.getAvatarById(pid, this.players.get(pid)) @@ -432,26 +432,28 @@ public class GameServer { }); } - private void sendInPlayersLocation(long playerId, CommandType type, Object obj) { - this.sendInLocation(players.get(playerId).getLocationId(), type, obj); + private void sendInPlayersLocation(int playerId, CommandType type, Object obj) { + Player player = this.players.get(playerId); + this.sendInLocation(player.getLocationId(), player.getHomeId(), type, obj); } - private void sendInLocation(int locationId, CommandType type, Object obj) { + private void sendInLocation(int locationId, long playersHome, CommandType type, Object obj) { players.keySet().forEach(k -> { if( locationId != players.get(k).getLocationId() ) return; + if( locationId == -1 && players.get(k).getHomeId() != playersHome) return; this.call(k, type, obj); }); } - private void sendResult(long playerId, double tid, Object obj) { + private void sendResult(int playerId, double tid, Object obj) { this.sendMessage(playerId, new CallMessage("_result", tid, null, obj)); } - private void call(long playerId, CommandType function, Object obj) { + private void call(int playerId, CommandType function, Object obj) { this.sendMessage(playerId, new CallMessage(function.getValue(), 0d, null, obj)); } - private void sendMessage(long playerId, Object obj) { + private void sendMessage(int playerId, Object obj) { try { this.players.get(playerId) .getConnection() @@ -461,7 +463,7 @@ public class GameServer { } } - public void onDisconnect(long playerId) { + public void onDisconnect(int playerId) { log.warn("GameServer.onDisconnect() close: {}", playerId); if( !this.players.containsKey(playerId) ) return; this.deleteSelf(playerId, this.players.get(playerId).getLocationId()); diff --git a/src/main/java/com/alterdekim/game/component/ReferenceLoader.java b/src/main/java/com/alterdekim/game/component/ReferenceLoader.java index 062b598..ba673d0 100644 --- a/src/main/java/com/alterdekim/game/component/ReferenceLoader.java +++ b/src/main/java/com/alterdekim/game/component/ReferenceLoader.java @@ -10,7 +10,7 @@ public class ReferenceLoader { @Autowired private UserRepository userRepository; - public User getUserReference(Long userId) { + public User getUserReference(Integer userId) { return userRepository.getReferenceById(userId); } } diff --git a/src/main/java/com/alterdekim/game/component/game/ChatMessage.java b/src/main/java/com/alterdekim/game/component/game/ChatMessage.java index 5803b53..2904218 100644 --- a/src/main/java/com/alterdekim/game/component/game/ChatMessage.java +++ b/src/main/java/com/alterdekim/game/component/game/ChatMessage.java @@ -6,6 +6,6 @@ import lombok.Getter; @Getter @AllArgsConstructor public class ChatMessage { - private Long playerId; + private Integer playerId; private String text; } \ No newline at end of file diff --git a/src/main/java/com/alterdekim/game/component/game/Player.java b/src/main/java/com/alterdekim/game/component/game/Player.java index 83a8ae3..505c885 100644 --- a/src/main/java/com/alterdekim/game/component/game/Player.java +++ b/src/main/java/com/alterdekim/game/component/game/Player.java @@ -15,4 +15,5 @@ public class Player { private double y; private int locationId; private double state; + private long homeId; } diff --git a/src/main/java/com/alterdekim/game/component/game/SetPlayerPosition.java b/src/main/java/com/alterdekim/game/component/game/SetPlayerPosition.java index a737ad6..c3c6bfa 100644 --- a/src/main/java/com/alterdekim/game/component/game/SetPlayerPosition.java +++ b/src/main/java/com/alterdekim/game/component/game/SetPlayerPosition.java @@ -6,7 +6,7 @@ import lombok.Getter; @Getter @AllArgsConstructor public class SetPlayerPosition { - private Long userId; + private Integer userId; private Point point; private Long tweenerId; } diff --git a/src/main/java/com/alterdekim/game/component/game/SetPlayerState.java b/src/main/java/com/alterdekim/game/component/game/SetPlayerState.java index 1131e85..41aaf7d 100644 --- a/src/main/java/com/alterdekim/game/component/game/SetPlayerState.java +++ b/src/main/java/com/alterdekim/game/component/game/SetPlayerState.java @@ -6,6 +6,6 @@ import lombok.Getter; @Getter @AllArgsConstructor public class SetPlayerState { - private Long playerId; + private Integer playerId; private Double state; } diff --git a/src/main/java/com/alterdekim/game/component/game/Shoot.java b/src/main/java/com/alterdekim/game/component/game/Shoot.java index 5d766ab..b80c11c 100644 --- a/src/main/java/com/alterdekim/game/component/game/Shoot.java +++ b/src/main/java/com/alterdekim/game/component/game/Shoot.java @@ -6,7 +6,7 @@ import lombok.Getter; @Getter @AllArgsConstructor public class Shoot { - private Long playerId; + private Integer playerId; private Double x; private Double y; } diff --git a/src/main/java/com/alterdekim/game/component/game/UseMagicAbility.java b/src/main/java/com/alterdekim/game/component/game/UseMagicAbility.java index 8c7f43d..df11123 100644 --- a/src/main/java/com/alterdekim/game/component/game/UseMagicAbility.java +++ b/src/main/java/com/alterdekim/game/component/game/UseMagicAbility.java @@ -4,6 +4,6 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class UseMagicAbility { - private Long userId; + private Integer userId; private Integer magicId; } diff --git a/src/main/java/com/alterdekim/game/component/game/friends/UserFriend.java b/src/main/java/com/alterdekim/game/component/game/friends/UserFriend.java index 0eca26f..516f270 100644 --- a/src/main/java/com/alterdekim/game/component/game/friends/UserFriend.java +++ b/src/main/java/com/alterdekim/game/component/game/friends/UserFriend.java @@ -8,7 +8,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class UserFriend { @AMFKey(name = "UserId") - private Long userId; + private Integer userId; @AMFKey(name = "SnName") private String snName; diff --git a/src/main/java/com/alterdekim/game/component/game/response/init/UserInfo.java b/src/main/java/com/alterdekim/game/component/game/response/init/UserInfo.java index 4d7cc54..c672bf9 100644 --- a/src/main/java/com/alterdekim/game/component/game/response/init/UserInfo.java +++ b/src/main/java/com/alterdekim/game/component/game/response/init/UserInfo.java @@ -24,10 +24,10 @@ import java.util.List; @JacksonXmlRootElement(localName = "user") public class UserInfo { @JacksonXmlProperty(isAttribute = true, localName = "UserId") - private Long userId; + private Integer userId; @JacksonXmlProperty(isAttribute = true, localName = "Id") - private Long id; + private Integer id; @JacksonXmlProperty(isAttribute = true, localName = "RoleFlags") @JsonSerialize(using = RoleFlagsSerializer.class) diff --git a/src/main/java/com/alterdekim/game/component/game/response/location/AddUserToLocation.java b/src/main/java/com/alterdekim/game/component/game/response/location/AddUserToLocation.java index 4317245..381fef1 100644 --- a/src/main/java/com/alterdekim/game/component/game/response/location/AddUserToLocation.java +++ b/src/main/java/com/alterdekim/game/component/game/response/location/AddUserToLocation.java @@ -5,6 +5,6 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class AddUserToLocation { - private Long playerId; + private Integer playerId; private PlayerAvatar avatar; } diff --git a/src/main/java/com/alterdekim/game/component/game/response/location/LocationObject.java b/src/main/java/com/alterdekim/game/component/game/response/location/LocationObject.java index b2fe3a9..cc01515 100644 --- a/src/main/java/com/alterdekim/game/component/game/response/location/LocationObject.java +++ b/src/main/java/com/alterdekim/game/component/game/response/location/LocationObject.java @@ -49,7 +49,7 @@ public class LocationObject { private String name; @JacksonXmlProperty(isAttribute = true, localName = "OwnerId") - private Long ownerId; + private Integer ownerId; @JacksonXmlProperty(isAttribute = true, localName = "OwnerName") private String ownerName; diff --git a/src/main/java/com/alterdekim/game/component/rtmp/ConnectedProcessor.java b/src/main/java/com/alterdekim/game/component/rtmp/ConnectedProcessor.java index 8415abb..7587956 100644 --- a/src/main/java/com/alterdekim/game/component/rtmp/ConnectedProcessor.java +++ b/src/main/java/com/alterdekim/game/component/rtmp/ConnectedProcessor.java @@ -21,7 +21,7 @@ public class ConnectedProcessor extends ConnectionProcessor { private final List message; private byte lastStreamId; private final GameServer gameServer; - private Long playerId; + private Integer playerId; private final RTMPSession rtmpSessionInfo; public ConnectedProcessor(InputStream inputStream, OutputStream outputStream, Socket sock, GameServer gameServer) { @@ -167,7 +167,7 @@ public class ConnectedProcessor extends ConnectionProcessor { if( !mr.isEmpty() && mr.get(0).getType() == AMFValueType.STRING && mr.get(0).getValue().equals("connect") ) { - this.playerId = Long.parseLong((String) mr.get(3).getValue()); + this.playerId = Integer.parseInt((String) mr.get(3).getValue()); this.gameServer.onConnect(this.playerId, (String) mr.get(5).getValue(), this); this.getOutputStream().write( StringUtils.hexStringToByteArray("020000000000040500000000002625A0020000000000050600000000002625A00202000000000004010000000000001000030000000000F214000000000200075F726573756C74003FF0000000000000030006666D7356657202000E464D532F342C302C302C31313231000C6361706162696C697469657300406FE0000000000000046D6F6465003FF00000000000000000090300056C6576656C0200067374617475730004636F646502001D4E6574436F6E6E656374696F6E2E436F6E6E6563742E53756363657373000B6465736372697074696F6E020015436F6E6E656374696F6E207375636365656465642E000E6F626A656374456E636F64696E670000000000000000000004646174610800000000000776657273696F6E02000A342C302C302C31313231000009000009") ); diff --git a/src/main/java/com/alterdekim/game/controller/SignUpController.java b/src/main/java/com/alterdekim/game/controller/SignUpController.java index 3109e65..16a9afc 100644 --- a/src/main/java/com/alterdekim/game/controller/SignUpController.java +++ b/src/main/java/com/alterdekim/game/controller/SignUpController.java @@ -103,7 +103,7 @@ public class SignUpController { return ResponseEntity.badRequest().body("bad_credentials_format"); } - long userId = userService.saveUser(username, password, Role.RoleType.RoleUser); + int userId = userService.saveUser(username, password, Role.RoleType.RoleUser); avatarInventoryService.addPhoneToInventory(userId, 1L); avatarInventoryService.addBackgroundToInventory(userId, 339L); diff --git a/src/main/java/com/alterdekim/game/controller/result/async/ServerActionUser.java b/src/main/java/com/alterdekim/game/controller/result/async/ServerActionUser.java index fc4db13..d4db24d 100644 --- a/src/main/java/com/alterdekim/game/controller/result/async/ServerActionUser.java +++ b/src/main/java/com/alterdekim/game/controller/result/async/ServerActionUser.java @@ -17,7 +17,7 @@ import java.time.LocalDateTime; public class ServerActionUser extends ServerActionCData { @JacksonXmlProperty(isAttribute = true, localName = "UserId") - private Long userId; + private Integer userId; @JacksonXmlProperty(isAttribute = true) private String hwId; diff --git a/src/main/java/com/alterdekim/game/entity/PhoneMessage.java b/src/main/java/com/alterdekim/game/entity/PhoneMessage.java index cdc3afe..3a18ad9 100644 --- a/src/main/java/com/alterdekim/game/entity/PhoneMessage.java +++ b/src/main/java/com/alterdekim/game/entity/PhoneMessage.java @@ -30,11 +30,11 @@ public class PhoneMessage { @JacksonXmlProperty(isAttribute = true, localName = "SenderId") @Column(nullable = false) - private Long senderId; + private Integer senderId; @JsonIgnore @Column(nullable = false) - private Long receiverId; + private Integer receiverId; @JacksonXmlProperty(isAttribute = true, localName = "SenderName") @Column(nullable = false) diff --git a/src/main/java/com/alterdekim/game/entity/Postcard.java b/src/main/java/com/alterdekim/game/entity/Postcard.java index 8829868..dffd7dd 100644 --- a/src/main/java/com/alterdekim/game/entity/Postcard.java +++ b/src/main/java/com/alterdekim/game/entity/Postcard.java @@ -30,10 +30,10 @@ public class Postcard { @JacksonXmlProperty(isAttribute = true, localName = "SenderId") @Column(nullable = false) - private Long senderId; + private Integer senderId; @Column(nullable = false) - private Long receiverId; + private Integer receiverId; @JacksonXmlProperty(isAttribute = true, localName = "SenderName") @Column(nullable = false) diff --git a/src/main/java/com/alterdekim/game/entity/Relationship.java b/src/main/java/com/alterdekim/game/entity/Relationship.java index 55e5456..b903d21 100644 --- a/src/main/java/com/alterdekim/game/entity/Relationship.java +++ b/src/main/java/com/alterdekim/game/entity/Relationship.java @@ -16,10 +16,10 @@ public class Relationship { private Long id; @Column(nullable = false) - private Long senderId; + private Integer senderId; @Column(nullable = false) - private Long recepientId; + private Integer recepientId; @Enumerated(value = EnumType.STRING) private FriendshipStatus status; diff --git a/src/main/java/com/alterdekim/game/entity/User.java b/src/main/java/com/alterdekim/game/entity/User.java index 246fed2..b044924 100644 --- a/src/main/java/com/alterdekim/game/entity/User.java +++ b/src/main/java/com/alterdekim/game/entity/User.java @@ -30,7 +30,7 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Integer id; @Column(nullable = false, unique = true) private String username; @@ -49,7 +49,7 @@ public class User { @Column(nullable = false) private Boolean isBanned = false; - public User(Long id, String username) { + public User(Integer id, String username) { this.id = id; this.username = username; } diff --git a/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java b/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java index 743ef02..ce847aa 100644 --- a/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java +++ b/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java @@ -21,28 +21,28 @@ import java.util.Optional; public interface AvatarInventoryRepository extends JpaRepository { @Query(value = "SELECT a FROM AvatarInventory a WHERE a.user.id = :uid AND a.type = :type") - List findItemsByUserIdAndType(@Param("uid") Long userId, @Param("type") AvatarInventoryType type); + List findItemsByUserIdAndType(@Param("uid") Integer userId, @Param("type") AvatarInventoryType type); @Query(value = "SELECT a FROM AvatarInventory a WHERE a.user.id = :uid AND a.type = :type AND a.isUsed = true") - List findUsedItemsByUserIdAndType(@Param("uid") Long userId, @Param("type") AvatarInventoryType type); + List findUsedItemsByUserIdAndType(@Param("uid") Integer userId, @Param("type") AvatarInventoryType type); @Query(value = "SELECT a FROM AvatarInventory a WHERE a.user.id = :uid AND a.type = :type AND a.goodId = :good_id") - Optional findSpecificitem(@Param("uid") Long userId, @Param("type") AvatarInventoryType type, @Param("good_id") Long goodId); + Optional findSpecificitem(@Param("uid") Integer userId, @Param("type") AvatarInventoryType type, @Param("good_id") Long goodId); @Transactional @Modifying @Query(value = "UPDATE AvatarInventory a SET a.isUsed = false WHERE a.user.id = :userId AND a.type = :type") - void resetUsed(@Param("userId") Long userId, @Param("type") AvatarInventoryType type); + void resetUsed(@Param("userId") Integer userId, @Param("type") AvatarInventoryType type); @Transactional @Modifying @Query(value = "UPDATE AvatarInventory a SET a.isUsed = true WHERE a.user.id = :userId AND a.type = :type AND a.goodId = :goodId") - void setUsed(@Param("userId") Long userId, @Param("goodId") Long goodId, @Param("type") AvatarInventoryType type); + void setUsed(@Param("userId") Integer userId, @Param("goodId") Long goodId, @Param("type") AvatarInventoryType type); @Transactional @Modifying @Query(value = "UPDATE AvatarInventory a SET a.color = :color WHERE a.user.id = :userId AND a.type = :type AND a.goodId = :goodId") - void setColor(@Param("userId") Long userId, @Param("goodId") Long goodId, @Param("type") AvatarInventoryType type, @Param("color") Integer color); + void setColor(@Param("userId") Integer userId, @Param("goodId") Long goodId, @Param("type") AvatarInventoryType type, @Param("color") Integer color); @Query(value = """ SELECT @@ -62,7 +62,7 @@ public interface AvatarInventoryRepository extends JpaRepository findInventoryItems(@Param("uid") Long userId, @Param("goodTypeId") GoodClothType goodClothType); + List findInventoryItems(@Param("uid") Integer userId, @Param("goodTypeId") GoodClothType goodClothType); @Query(value = """ SELECT @@ -81,7 +81,7 @@ public interface AvatarInventoryRepository extends JpaRepository findBackgrounds(@Param("uid") Long userId); + List findBackgrounds(@Param("uid") Integer userId); @Query(value = """ SELECT @@ -100,7 +100,7 @@ public interface AvatarInventoryRepository extends JpaRepository findPhones(@Param("uid") Long userId); + List findPhones(@Param("uid") Integer userId); @Query(value = """ SELECT @@ -116,7 +116,7 @@ public interface AvatarInventoryRepository extends JpaRepository findUsedBodyPartsByUserId(@Param("uid") Long userId); + List findUsedBodyPartsByUserId(@Param("uid") Integer userId); @Query(value = """ SELECT @@ -132,7 +132,7 @@ public interface AvatarInventoryRepository extends JpaRepository findUsedClothesByUserId(@Param("uid") Long userId, @Param("goodTypeId") GoodClothType goodClothType); + List findUsedClothesByUserId(@Param("uid") Integer userId, @Param("goodTypeId") GoodClothType goodClothType); @Query(value = """ @@ -143,8 +143,8 @@ public interface AvatarInventoryRepository extends JpaRepository findMagicAbilitiesByUserId(@Param("uid") Long userId); + List findMagicAbilitiesByUserId(@Param("uid") Integer userId); @Query(value = "SELECT s FROM Smile s WHERE s.id IN (SELECT a.goodId FROM AvatarInventory a WHERE a.user.id = :uid AND a.type = 'Smile')") - List findSmilesByUserId(@Param("uid") Long userId); + List findSmilesByUserId(@Param("uid") Integer userId); } diff --git a/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java b/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java index dcec6ec..e9a9219 100644 --- a/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java +++ b/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java @@ -57,5 +57,5 @@ public interface BodyPartRepository extends JpaRepository { ) AS a WHERE a.`type` = :#{#type.name()} GROUP BY a.id, a.`type`, a.media_resource_id, a.is_colorable""", nativeQuery = true) - List findInventoryItems(@Param("uid") Long userId, @Param("type") BodyPartType type); + List findInventoryItems(@Param("uid") Integer userId, @Param("type") BodyPartType type); } \ No newline at end of file diff --git a/src/main/java/com/alterdekim/game/repository/OnlineStatusRepository.java b/src/main/java/com/alterdekim/game/repository/OnlineStatusRepository.java index 0070553..def79eb 100644 --- a/src/main/java/com/alterdekim/game/repository/OnlineStatusRepository.java +++ b/src/main/java/com/alterdekim/game/repository/OnlineStatusRepository.java @@ -15,7 +15,7 @@ import java.util.Optional; public interface OnlineStatusRepository extends JpaRepository { @Query(value = "SELECT o FROM OnlineStatus o WHERE o.user.id = :userId") - List findByUserId(@Param("userId") Long userId); + List findByUserId(@Param("userId") Integer userId); @Query(value = "SELECT o FROM OnlineStatus o WHERE o.lastPingUnix < :pingTime") List listPingsOlderThan(@Param("pingTime") Long pingTime); diff --git a/src/main/java/com/alterdekim/game/repository/PhoneMessageRepository.java b/src/main/java/com/alterdekim/game/repository/PhoneMessageRepository.java index b32b7bf..8fd8c38 100644 --- a/src/main/java/com/alterdekim/game/repository/PhoneMessageRepository.java +++ b/src/main/java/com/alterdekim/game/repository/PhoneMessageRepository.java @@ -17,7 +17,7 @@ public interface PhoneMessageRepository extends JpaRepository findById(Long id); @Query(value = "SELECT p FROM PhoneMessage p WHERE p.receiverId = :uid") - List findByReceiverId(@Param("uid") Long id); + List findByReceiverId(@Param("uid") Integer id); List findAll(); diff --git a/src/main/java/com/alterdekim/game/repository/PostcardRepository.java b/src/main/java/com/alterdekim/game/repository/PostcardRepository.java index b8fda66..6c00033 100644 --- a/src/main/java/com/alterdekim/game/repository/PostcardRepository.java +++ b/src/main/java/com/alterdekim/game/repository/PostcardRepository.java @@ -19,7 +19,7 @@ public interface PostcardRepository extends JpaRepository { List findAll(); @Query(value = "SELECT p FROM Postcard p WHERE p.receiverId = :user_id") - List findByReceiverId(@Param("user_id") Long userId); + List findByReceiverId(@Param("user_id") Integer userId); @Transactional @Modifying diff --git a/src/main/java/com/alterdekim/game/repository/RelationshipRepository.java b/src/main/java/com/alterdekim/game/repository/RelationshipRepository.java index 72ed865..d92c199 100644 --- a/src/main/java/com/alterdekim/game/repository/RelationshipRepository.java +++ b/src/main/java/com/alterdekim/game/repository/RelationshipRepository.java @@ -15,7 +15,7 @@ import java.util.Optional; @Repository public interface RelationshipRepository extends JpaRepository { @Query(value = "SELECT r FROM Relationship r WHERE ((r.senderId = :userf AND r.recepientId = :users) OR (r.senderId = :users AND r.recepientId = :userf)) AND r.status = :rel") - Optional findRelation(@Param("userf") Long userId, @Param("users") Long userId1, @Param("rel") Relationship.FriendshipStatus state); + Optional findRelation(@Param("userf") Integer userId, @Param("users") Integer userId1, @Param("rel") Relationship.FriendshipStatus state); @Transactional @Modifying @@ -40,7 +40,7 @@ public interface RelationshipRepository extends JpaRepository findFriendsOfUserById(@Param("uid") Long userId); + List findFriendsOfUserById(@Param("uid") Integer userId); @Query(value = """ SELECT new User(r.userId, u.username) @@ -53,12 +53,12 @@ public interface RelationshipRepository extends JpaRepository findRequestsOfUserById(@Param("uid") Long userId); + List findRequestsOfUserById(@Param("uid") Integer userId); @Transactional @Modifying @Query(value = "DELETE FROM Relationship r WHERE ((r.senderId = :uidf AND r.recepientId = :uids) OR (r.senderId = :uids AND r.recepientId = :uidf)) AND r.status = com.alterdekim.game.entity.Relationship$FriendshipStatus.Friendship") - void deleteFriendshipByUserIds(@Param("uidf") Long userId1, @Param("uids") Long userId2); + void deleteFriendshipByUserIds(@Param("uidf") Integer userId1, @Param("uids") Integer userId2); @Transactional @Modifying @@ -71,7 +71,7 @@ public interface RelationshipRepository extends JpaRepository users); + void acceptFriendshipWithUsers(@Param("uid") Integer userId, @Param("l") List users); @Transactional @Modifying @@ -82,5 +82,5 @@ public interface RelationshipRepository extends JpaRepository users); + void denyFriendshipsWithUsers(@Param("uid") Integer userId, @Param("l") List users); } diff --git a/src/main/java/com/alterdekim/game/repository/UserPropertyRepository.java b/src/main/java/com/alterdekim/game/repository/UserPropertyRepository.java index d1fb8af..a16bbc2 100644 --- a/src/main/java/com/alterdekim/game/repository/UserPropertyRepository.java +++ b/src/main/java/com/alterdekim/game/repository/UserPropertyRepository.java @@ -17,12 +17,12 @@ public interface UserPropertyRepository extends JpaRepository findById(Long id); @Query(value = "SELECT u FROM UserProperty u WHERE u.user.id = :uid AND u.type = :type") - Optional findByUserIdAndTag(@Param("uid") Long userId, @Param("type") PlayerProperties property); + Optional findByUserIdAndTag(@Param("uid") Integer userId, @Param("type") PlayerProperties property); List findAll(); @Transactional @Modifying @Query(value = "DELETE FROM UserProperty u WHERE u.user.id = :uid AND u.type = :type") - void deleteByUserIdAndType(@Param("uid") Long userId, @Param("type") PlayerProperties properties); + void deleteByUserIdAndType(@Param("uid") Integer userId, @Param("type") PlayerProperties properties); } diff --git a/src/main/java/com/alterdekim/game/repository/UserRepository.java b/src/main/java/com/alterdekim/game/repository/UserRepository.java index ce1e246..00b2083 100644 --- a/src/main/java/com/alterdekim/game/repository/UserRepository.java +++ b/src/main/java/com/alterdekim/game/repository/UserRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { User findByUsername(String username); @Query(value = "SELECT COUNT(u) FROM User u") diff --git a/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java b/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java index decefc3..5507e7e 100644 --- a/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java +++ b/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java @@ -57,28 +57,28 @@ public class AvatarInventoryService { @Autowired private PhoneIconService phoneIconService; - public void setDefault(Long userId, Long goodId, AvatarInventoryType type) { + public void setDefault(Integer userId, Long goodId, AvatarInventoryType type) { this.inventoryRepository.resetUsed(userId, type); this.inventoryRepository.setUsed(userId, goodId, type); } - public void setUsed(Long userId, Long goodId, AvatarInventoryType type) { + public void setUsed(Integer userId, Long goodId, AvatarInventoryType type) { this.inventoryRepository.setUsed(userId, goodId, type); } - public void resetUsed(Long userId, AvatarInventoryType type) { + public void resetUsed(Integer userId, AvatarInventoryType type) { this.inventoryRepository.resetUsed(userId, type); } - public void setColor(Long userId, Long goodId, AvatarInventoryType type, Integer color) { + public void setColor(Integer userId, Long goodId, AvatarInventoryType type, Integer color) { this.inventoryRepository.setColor(userId, goodId, type, color); } - public boolean isSpecificItemExists(Long userId, AvatarInventoryType type, Long goodId) { + public boolean isSpecificItemExists(Integer userId, AvatarInventoryType type, Long goodId) { return this.inventoryRepository.findSpecificitem(userId, type, goodId).isPresent(); } - public InventoryGroup getBodyPartInventoryGroup(Long userId, BodyPartType type, boolean addEmpty) { + public InventoryGroup getBodyPartInventoryGroup(Integer userId, BodyPartType type, boolean addEmpty) { return new InventoryGroup( type.getValue(), type.getTextResourceId(), @@ -149,7 +149,7 @@ public class AvatarInventoryService { ); } - public InventoryGroup getClothInventoryGroup(Long userId, GoodClothType type) { + public InventoryGroup getClothInventoryGroup(Integer userId, GoodClothType type) { return new InventoryGroup( type.getVal().getGoodType(), type.getTextResourceId(), @@ -160,7 +160,7 @@ public class AvatarInventoryService { ); } - public List getWholeAvatarByUserId(Long userId) { + public List getWholeAvatarByUserId(Integer userId) { return Stream.of(this.inventoryRepository.findUsedBodyPartsByUserId(userId), this.inventoryRepository.findUsedClothesByUserId(userId, GoodClothType.Clothes), this.inventoryRepository.findUsedClothesByUserId(userId, GoodClothType.Caps), @@ -171,27 +171,27 @@ public class AvatarInventoryService { .flatMap(List::stream).collect(Collectors.toList()); } - public List getMagicAbilitiesItemsByUserId(Long userId) { + public List getMagicAbilitiesItemsByUserId(Integer userId) { return this.inventoryRepository.findMagicAbilitiesByUserId(userId); // todo: implement expiration ability } - public List getSmilesByUserId(Long userId) { + public List getSmilesByUserId(Integer userId) { return this.inventoryRepository.findSmilesByUserId(userId); } - public List getBackgroundsByUserId(Long userId) { + public List getBackgroundsByUserId(Integer userId) { return this.inventoryRepository.findBackgrounds(userId); } - public List getPhonesByUserId(Long userId) { + public List getPhonesByUserId(Integer userId) { return this.inventoryRepository.findPhones(userId); } - public void addPhoneToInventory(Long userId, Long phoneId) { + public void addPhoneToInventory(Integer userId, Long phoneId) { this.inventoryRepository.save(new AvatarInventory(referenceLoader.getUserReference(userId), phoneId, true, AvatarInventoryType.Phones, 0)); } - public void addBackgroundToInventory(Long userId, Long backgroundId) { + public void addBackgroundToInventory(Integer userId, Long backgroundId) { this.inventoryRepository.save(new AvatarInventory(referenceLoader.getUserReference(userId), backgroundId, true, AvatarInventoryType.Backgrounds, 0)); } @@ -213,28 +213,28 @@ public class AvatarInventoryService { .collect(Collectors.toList()); } - public Long getSelectedPhoneId(Long userId) { + public Long getSelectedPhoneId(Integer userId) { return this.inventoryRepository.findUsedItemsByUserIdAndType(userId, AvatarInventoryType.Phones) .stream() .map(AvatarInventory::getGoodId) .findFirst().orElse(0L); } - public Long getUsedBackground(Long userId) { + public Long getUsedBackground(Integer userId) { return this.inventoryRepository.findUsedItemsByUserIdAndType(userId, AvatarInventoryType.Backgrounds) .stream() .map(AvatarInventory::getGoodId) .findFirst().orElse(0L); } - public Long getUsedHouse(Long userId) { + public Long getUsedHouse(Integer userId) { return this.inventoryRepository.findUsedItemsByUserIdAndType(userId, AvatarInventoryType.House) .stream() .map(AvatarInventory::getGoodId) .findFirst().orElse(0L); } - public String getAchievementsByUserId(Long userId) { + public String getAchievementsByUserId(Integer userId) { return this.inventoryRepository.findItemsByUserIdAndType(userId, AvatarInventoryType.Achievements) .stream() .map(a -> a.getGoodId().toString()) diff --git a/src/main/java/com/alterdekim/game/service/LocationService.java b/src/main/java/com/alterdekim/game/service/LocationService.java index b66c965..90b3779 100644 --- a/src/main/java/com/alterdekim/game/service/LocationService.java +++ b/src/main/java/com/alterdekim/game/service/LocationService.java @@ -46,7 +46,7 @@ public class LocationService { Optional l = this.repository.findDefaultLocation(); if( l.isPresent() ) { Location r = l.get(); - return new LocationObject(r.getLocationId(), false, false, false, true, r.getMediaResourceId(), r.getX(), r.getY(), r.getName(), 0L, "", this.locationObjectInstanceRepository.findObjectsForLocationById(r.getLocationId())); + return new LocationObject(r.getLocationId(), false, false, false, true, r.getMediaResourceId(), r.getX(), r.getY(), r.getName(), 0, "", this.locationObjectInstanceRepository.findObjectsForLocationById(r.getLocationId())); } return new LocationObject(); } @@ -55,7 +55,7 @@ public class LocationService { Optional l = this.repository.findLocationById(locationId); if( l.isPresent() ) { Location r = l.get(); - return new LocationObject(r.getLocationId(), false, false, false, true, r.getMediaResourceId(), r.getX(), r.getY(), r.getName(), 0L, "", this.locationObjectInstanceRepository.findObjectsForLocationById(locationId)); + return new LocationObject(r.getLocationId(), false, false, false, true, r.getMediaResourceId(), r.getX(), r.getY(), r.getName(), 0, "", this.locationObjectInstanceRepository.findObjectsForLocationById(locationId)); } return getDefaultLocation(); } @@ -77,7 +77,7 @@ public class LocationService { } - public LocationObject getHomeByUserId(Long userId) { + public LocationObject getHomeByUserId(Integer userId) { Long goodId = goodRepository.findById(avatarInventoryService.getUsedHouse(userId)).map(Good::getId).orElse(102L); var house = this.houseLocationRepository.findDefaultHouseLocationByGoodId(goodId).get(); return new LocationObject(-1L, true, false, userService.getBooleanUserProperty(userId, PlayerProperties.IsHomeLocked, true), true, house.getMediaResourceId().longValue(), 300.0, 300.0, "", userId, userService.getUsernameById(userId).get(), Collections.emptyList()); diff --git a/src/main/java/com/alterdekim/game/service/OnlineStatusService.java b/src/main/java/com/alterdekim/game/service/OnlineStatusService.java index eae15e3..5cfcdbd 100644 --- a/src/main/java/com/alterdekim/game/service/OnlineStatusService.java +++ b/src/main/java/com/alterdekim/game/service/OnlineStatusService.java @@ -21,15 +21,15 @@ public class OnlineStatusService { @Autowired private ReferenceLoader referenceLoader; - public List findByUserId(Long userId) { + public List findByUserId(Integer userId) { return this.repository.findByUserId(userId); } - public void setOnlineFor(Long userId) { + public void setOnlineFor(Integer userId) { this.repository.save(new OnlineStatus(referenceLoader.getUserReference(userId), System.currentTimeMillis() / 1000L)); } - public Boolean isOnline(Long userId) { + public Boolean isOnline(Integer userId) { return !this.findByUserId(userId).isEmpty(); } diff --git a/src/main/java/com/alterdekim/game/service/PhoneMessageService.java b/src/main/java/com/alterdekim/game/service/PhoneMessageService.java index f4b8109..88dea8d 100644 --- a/src/main/java/com/alterdekim/game/service/PhoneMessageService.java +++ b/src/main/java/com/alterdekim/game/service/PhoneMessageService.java @@ -18,7 +18,7 @@ public class PhoneMessageService { return repository.findAll(); } - public List getAllByReceiverId(Long id) { + public List getAllByReceiverId(Integer id) { return repository.findByReceiverId(id); } diff --git a/src/main/java/com/alterdekim/game/service/PostcardService.java b/src/main/java/com/alterdekim/game/service/PostcardService.java index 5f217df..9bf6924 100644 --- a/src/main/java/com/alterdekim/game/service/PostcardService.java +++ b/src/main/java/com/alterdekim/game/service/PostcardService.java @@ -19,7 +19,7 @@ public class PostcardService { return repository.findAll(); } - public List getAllPostcardsOfUser(Long userId) { + public List getAllPostcardsOfUser(Integer userId) { return this.repository.findByReceiverId(userId); } diff --git a/src/main/java/com/alterdekim/game/service/RelationshipService.java b/src/main/java/com/alterdekim/game/service/RelationshipService.java index f2a4f3c..cd7e307 100644 --- a/src/main/java/com/alterdekim/game/service/RelationshipService.java +++ b/src/main/java/com/alterdekim/game/service/RelationshipService.java @@ -19,11 +19,11 @@ public class RelationshipService { this.repository.save(relationship); } - public Boolean isFriends(Long userId, Long userId1) { + public Boolean isFriends(Integer userId, Integer userId1) { return this.repository.findRelation(userId, userId1, Relationship.FriendshipStatus.Friendship).isPresent(); } - public Optional isRequestSent(Long userId, Long userId1) { + public Optional isRequestSent(Integer userId, Integer userId1) { return this.repository.findRelation(userId, userId1, Relationship.FriendshipStatus.Request); } @@ -35,7 +35,7 @@ public class RelationshipService { this.repository.acceptRequestById(id); } - public void sendRequest(Long sender, Long receiver) { + public void sendRequest(Integer sender, Integer receiver) { if( this.isFriends(sender, receiver) ) return; if( this.isRequestSent(sender, receiver).isPresent() ) { Relationship r = this.isRequestSent(sender, receiver).get(); @@ -46,23 +46,23 @@ public class RelationshipService { this.repository.save(new Relationship(null, sender, receiver, Relationship.FriendshipStatus.Request)); } - public void deleteFriendshipByUserIds(Long userId1, Long userId2) { + public void deleteFriendshipByUserIds(Integer userId1, Integer userId2) { this.repository.deleteFriendshipByUserIds(userId1, userId2); } - public List getFriendsOfUser(Long userId) { + public List getFriendsOfUser(Integer userId) { return this.repository.findFriendsOfUserById(userId); } - public List getRequestsOfUser(Long userId) { + public List getRequestsOfUser(Integer userId) { return this.repository.findRequestsOfUserById(userId); } - public void acceptFriendshipWithUsers(Long userId, List users) { + public void acceptFriendshipWithUsers(Integer userId, List users) { this.repository.acceptFriendshipWithUsers(userId, users); } - public void denyFriendshipsWithUsers(Long userId, List users) { + public void denyFriendshipsWithUsers(Integer userId, List users) { this.repository.denyFriendshipsWithUsers(userId, users); } } diff --git a/src/main/java/com/alterdekim/game/service/UserService.java b/src/main/java/com/alterdekim/game/service/UserService.java index fcfb917..ea329ce 100644 --- a/src/main/java/com/alterdekim/game/service/UserService.java +++ b/src/main/java/com/alterdekim/game/service/UserService.java @@ -58,7 +58,7 @@ public class UserService { return userRepository.findByUsername(username); } - public long saveUser(String username, String password, Role.RoleType role) { + public int saveUser(String username, String password, Role.RoleType role) { User user = new User(); user.setUsername(username); user.setPassword(passwordEncoder.encode(password)); @@ -74,7 +74,7 @@ public class UserService { return roleRepository.save(new Role(role)); } - public Optional findUserProperty(Long userId, PlayerProperties type) { + public Optional findUserProperty(Integer userId, PlayerProperties type) { Optional res = this.propertyRepository.findByUserIdAndTag(userId, type); if( res.isEmpty() ) return Optional.empty(); UserProperty property = res.get(); @@ -87,7 +87,7 @@ public class UserService { }); } - public void pushUserProperty(Long userId, PlayerProperties type, Object val) { + public void pushUserProperty(Integer userId, PlayerProperties type, Object val) { this.propertyRepository.deleteByUserIdAndType(userId, type); this.propertyRepository.save(switch (type.getValueType()) { case String -> new UserProperty(userRepository.getReferenceById(userId), (String) val, type); @@ -98,7 +98,7 @@ public class UserService { }); } - public RoleFlags getRoleFlags(Long userId) { + public RoleFlags getRoleFlags(Integer userId) { Optional res = this.findUserProperty(userId, PlayerProperties.RoleFlags); if( res.isEmpty() ) { this.pushUserProperty(userId, PlayerProperties.RoleFlags, RoleFlags.SA); @@ -107,12 +107,12 @@ public class UserService { return (RoleFlags) res.get(); } - public Boolean getIsClubPresent(Long userId) { + public Boolean getIsClubPresent(Integer userId) { // todo: Implement clubs; return false; } - public ClubAccessType getClubAccessType(Long userId) { + public ClubAccessType getClubAccessType(Integer userId) { Optional res = this.findUserProperty(userId, PlayerProperties.ClubAccessType); if( res.isEmpty() ) { this.pushUserProperty(userId, PlayerProperties.ClubAccessType, ClubAccessType.CLOSED); @@ -121,31 +121,31 @@ public class UserService { return (ClubAccessType) res.get(); } - public Boolean getIsFriend(Long userId, Long userId2) { + public Boolean getIsFriend(Integer userId, Integer userId2) { return relationshipService.isFriends(userId, userId2); } - public void setWeaponsCount(Long userId, Integer count) { + public void setWeaponsCount(Integer userId, Integer count) { this.pushUserProperty(userId, PlayerProperties.WeaponsCount, count); } - public Integer getUsualTickets(Long userId) { + public Integer getUsualTickets(Integer userId) { return this.getIntegerUserProperty(userId, PlayerProperties.UsualTickets, 1000); } - public void setUsualTickets(Long userId, Integer amount) { + public void setUsualTickets(Integer userId, Integer amount) { this.pushUserProperty(userId, PlayerProperties.UsualTickets, amount); } - public Integer getMagicTickets(Long userId) { + public Integer getMagicTickets(Integer userId) { return getIntegerUserProperty(userId, PlayerProperties.MagicTickets, 200); } - public void setMagicTickets(Long userId, Integer amount) { + public void setMagicTickets(Integer userId, Integer amount) { this.pushUserProperty(userId, PlayerProperties.MagicTickets, amount); } - public Integer getIntegerUserProperty(Long userId, PlayerProperties prop, Integer def) { + public Integer getIntegerUserProperty(Integer userId, PlayerProperties prop, Integer def) { Optional res = this.findUserProperty(userId, prop); if( res.isEmpty() ) { this.pushUserProperty(userId, prop, def); @@ -154,7 +154,7 @@ public class UserService { return res.map(o -> (Integer) o).get(); } - public Boolean getBooleanUserProperty(Long userId, PlayerProperties prop, Boolean def) { + public Boolean getBooleanUserProperty(Integer userId, PlayerProperties prop, Boolean def) { Optional res = this.findUserProperty(userId, prop); if( res.isEmpty() ) { this.pushUserProperty(userId, prop, def); @@ -163,11 +163,11 @@ public class UserService { return res.map(o -> (Boolean) o).get(); } - public Optional getUsernameById(Long userId) { + public Optional getUsernameById(Integer userId) { return this.userRepository.findById(userId).map(User::getUsername); } - public UserAccount getUserAccountByUserId(Long userId) { + public UserAccount getUserAccountByUserId(Integer userId) { return new UserAccount( getIntegerUserProperty(userId, PlayerProperties.PhoneCardBalance, 10), getIntegerUserProperty(userId, PlayerProperties.WeaponsCount, 15), @@ -175,19 +175,19 @@ public class UserService { ); } - public void setDefaultPhone(Long userId, Long phoneId) { + public void setDefaultPhone(Integer userId, Long phoneId) { this.setDefault(userId, phoneId, AvatarInventoryType.Phones); } - public void setDefaultBackground(Long userId, Long bgId) { + public void setDefaultBackground(Integer userId, Long bgId) { this.setDefault(userId, bgId, AvatarInventoryType.Backgrounds); } - private void setDefault(Long userId, Long gid, AvatarInventoryType type) { + private void setDefault(Integer userId, Long gid, AvatarInventoryType type) { this.inventoryService.setDefault(userId, gid, type); } - public void setDefaultInventoryItem(Long userId, Long gid, AvatarInventoryType type, Integer color) { + public void setDefaultInventoryItem(Integer userId, Long gid, AvatarInventoryType type, Integer color) { if( !this.inventoryService.isSpecificItemExists(userId, type, gid) ) { this.inventoryService.addGoodToInventory(new AvatarInventory(userRepository.getReferenceById(userId), gid, true, type, color)); } else { @@ -196,7 +196,7 @@ public class UserService { } } - public void resetUsedClothes(Long userId) { + public void resetUsedClothes(Integer userId) { this.inventoryService.resetUsed(userId, AvatarInventoryType.BodyParts); this.inventoryService.resetUsed(userId, AvatarInventoryType.Clothes_); this.inventoryService.resetUsed(userId, AvatarInventoryType.Caps); @@ -206,7 +206,7 @@ public class UserService { this.inventoryService.resetUsed(userId, AvatarInventoryType.Boots); } - public UserPhone getUserPhoneByUserId(Long userId) { + public UserPhone getUserPhoneByUserId(Integer userId) { Long phoneId = inventoryService.getSelectedPhoneId(userId); return new UserPhone( 999, @@ -216,7 +216,7 @@ public class UserService { ); } - public Inventory getUserAvatarByUserId(Long userId) { + public Inventory getUserAvatarByUserId(Integer userId) { return new Inventory( new InventoryTab(199, List.of( inventoryService.getBodyPartInventoryGroup(userId, BodyPartType.Body, false), @@ -245,7 +245,7 @@ public class UserService { ); } - public UserInfo getUserInfoByUserId(Long userId, boolean isForUserInit, Long plId) { + public UserInfo getUserInfoByUserId(Integer userId, boolean isForUserInit, Integer plId) { // todo: implement hardcoded stuff return new UserInfo( userId, @@ -286,11 +286,11 @@ public class UserService { ); } - public List getOtherUserAvatar(Long userId) { + public List getOtherUserAvatar(Integer userId) { return this.inventoryService.getWholeAvatarByUserId(userId); } - public UserInitInfo getUserInitInfoByUserId(Long userId) { + public UserInitInfo getUserInitInfoByUserId(Integer userId) { return new UserInitInfo( getUserAccountByUserId(userId), getUserInfoByUserId(userId, true, userId), @@ -300,7 +300,7 @@ public class UserService { ); } - public PlayerAvatar getAvatarById(long userId, Player p) { + public PlayerAvatar getAvatarById(int userId, Player p) { Map body = new HashMap<>(); List i = inventoryService.getWholeAvatarByUserId(userId).stream().map(BodyAvatarItem::fromInterface).collect(Collectors.toList()); IntStream.range(0, i.size()).boxed().forEach(g -> body.put(String.valueOf(g+1), i.get(g))); @@ -308,7 +308,7 @@ public class UserService { return new PlayerAvatar(String.valueOf(getRoleFlags(userId).getValue()), a); } - public void removeUser(long userId) { + public void removeUser(int userId) { this.userRepository.deleteById(userId); } @@ -316,15 +316,15 @@ public class UserService { return this.userRepository.findUsersCount(); } - public Map getFriendsOfUser(Long userId, Map players) { + public Map getFriendsOfUser(Integer userId, Map players) { return this.convertUsersToFriends(relationshipService.getFriendsOfUser(userId), players); } - public Map getRequestsOfUser(Long userId, Map players) { + public Map getRequestsOfUser(Integer userId, Map players) { return this.convertUsersToFriends(relationshipService.getRequestsOfUser(userId), players); } - private Map convertUsersToFriends(List l, Map players) { + private Map convertUsersToFriends(List l, Map players) { Map m = new HashMap<>(); for( int i = 0, u = 1; i < l.size(); i++, u++ ) { User user = l.get(i); @@ -333,19 +333,19 @@ public class UserService { return m; } - public void removeFriendshipWithUser(Long userId, Long friendId) { + public void removeFriendshipWithUser(Integer userId, Integer friendId) { relationshipService.deleteFriendshipByUserIds(userId, friendId); } - public void acceptFriendshipWithUsers(Long userId, List users) { + public void acceptFriendshipWithUsers(Integer userId, List users) { relationshipService.acceptFriendshipWithUsers(userId, users); } - public void denyFriendshipsWithUsers(Long userId, List users) { + public void denyFriendshipsWithUsers(Integer userId, List users) { relationshipService.denyFriendshipsWithUsers(userId, users); } - public void pushToInventory(long userId, AvatarInventoryType type, long goodId) { + public void pushToInventory(int userId, AvatarInventoryType type, long goodId) { this.inventoryService.addGoodToInventory(new AvatarInventory(userRepository.getReferenceById(userId), goodId, false, type)); } }