Skip to content

Commit b237b60

Browse files
committed
Prevent setting overlap slot
1 parent 2cb6f81 commit b237b60

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Server/src/database/DataBase.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,18 @@ public static void setSlot(User user, int slotIndex, int index) {
215215
"`no` = '" + user.getNo() + "';");
216216
rs.close();
217217
}
218-
219-
if (!(slotIndex >= 0 && slotIndex <= 9))
218+
if (slotIndex < 0 || slotIndex > 9) {
220219
return;
221-
222-
String itemType;
223-
itemType = "slot" + (slotIndex + 1);
224-
220+
}
221+
for (int i = 0; i < 10; ++i) {
222+
if (rs.getInt("slot" + i) == index) {
223+
return;
224+
}
225+
}
226+
String itemType = "slot" + slotIndex;
225227
connection.createStatement().executeUpdate("UPDATE `slot` SET " +
226228
"`" + itemType + "` = '" + index + "' " +
227229
"WHERE `no` = '" + user.getNo() + "';");
228-
229230
} catch (SQLException e) {
230231
logger.warning(e.toString());
231232
}
@@ -239,11 +240,10 @@ public static void delSlot(User user, int slotIndex) {
239240
"`no` = '" + user.getNo() + "';");
240241
rs.close();
241242
}
242-
if (!(slotIndex >= 0 && slotIndex <= 9)) {
243+
if (slotIndex < 0 || slotIndex > 9) {
243244
return;
244245
}
245-
String itemType;
246-
itemType = "slot" + (slotIndex + 1);
246+
String itemType = "slot" + slotIndex;
247247
connection.createStatement().executeUpdate("UPDATE `slot` SET " +
248248
"`" + itemType + "` = '" + -1 + "' " +
249249
"WHERE `no` = '" + user.getNo() + "';");

danbi.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Source Host: localhost
44
Source Database: danbi
55
Target Host: localhost
66
Target Database: danbi
7-
Date: 2017-08-01 ¿ÀÀü 1:57:32
7+
Date: 2017-08-01 ���� 1:57:32
88
*/
99

1010
SET FOREIGN_KEY_CHECKS=0;
@@ -246,6 +246,7 @@ CREATE TABLE `skill` (
246246
-- ----------------------------
247247
CREATE TABLE `slot` (
248248
`no` int(11) NOT NULL,
249+
`slot0` int(11) NOT NULL DEFAULT '-1',
249250
`slot1` int(11) NOT NULL DEFAULT '-1',
250251
`slot2` int(11) NOT NULL DEFAULT '-1',
251252
`slot3` int(11) NOT NULL DEFAULT '-1',
@@ -254,8 +255,7 @@ CREATE TABLE `slot` (
254255
`slot6` int(11) NOT NULL DEFAULT '-1',
255256
`slot7` int(11) NOT NULL DEFAULT '-1',
256257
`slot8` int(11) NOT NULL DEFAULT '-1',
257-
`slot9` int(11) NOT NULL DEFAULT '-1',
258-
`slot10` int(11) NOT NULL DEFAULT '-1'
258+
`slot9` int(11) NOT NULL DEFAULT '-1'
259259
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
260260

261261
-- ----------------------------
@@ -359,5 +359,5 @@ INSERT INTO `slot` VALUES ('19', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1',
359359
INSERT INTO `slot` VALUES ('20', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1');
360360
INSERT INTO `slot` VALUES ('21', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1');
361361
INSERT INTO `slot` VALUES ('22', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1');
362-
INSERT INTO `user` VALUES ('21', '1', 'PPAkXhcIYGcDVjdCgY/hHg==', 'cheapmunk', '0', '0', '1', '016-Thief01', '1', '0', '0', '0', '0', '0', '999', '0', '1', '0', '0', '1', '0', '10', '6', '4', '4', '0');
363-
INSERT INTO `user` VALUES ('22', '2', 'gKBvNUyp+H1+LZJgpXESyA==', 'jubinpark', '0', '0', '2', '053-Undead03', '1', '0', '0', '0', '0', '0', '1000', '0', '1', '0', '0', '1', '0', '8', '5', '8', '4', '0');
362+
INSERT INTO `user` VALUES ('21', '1', 'PPAkXhcIYGcDVjdCgY/hHg==', 'foo', '0', '0', '1', '016-Thief01', '1', '0', '0', '0', '0', '0', '999', '0', '1', '0', '0', '1', '0', '10', '6', '4', '4', '0');
363+
INSERT INTO `user` VALUES ('22', '2', 'gKBvNUyp+H1+LZJgpXESyA==', 'bar', '0', '0', '2', '053-Undead03', '1', '0', '0', '0', '0', '0', '1000', '0', '1', '0', '0', '1', '0', '8', '5', '8', '4', '0');

0 commit comments

Comments
 (0)