• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisãoffe2678929201cd2bf4ab3f068a489bc6ee18e78 (tree)
Hora2019-01-17 05:33:19
Autorsebastian_bugiu <sebastian_ <bugiu@head...>
Commitersebastian_bugiu <sebastian_

Mensagem de Log

Adding lobby support.

Mudança Sumário

Diff

diff -r 3108183fea89 -r ffe267892920 src/headwayEnt/headwayEnt/Blackhole_Darksun_WebServer/ErrorCodes.java
--- a/src/headwayEnt/headwayEnt/Blackhole_Darksun_WebServer/ErrorCodes.java Tue Jan 15 22:50:18 2019 +0200
+++ b/src/headwayEnt/headwayEnt/Blackhole_Darksun_WebServer/ErrorCodes.java Wed Jan 16 22:33:19 2019 +0200
@@ -157,4 +157,10 @@
157157
158158 public static final int CREATE_LOBBY_TOO_MANY_INVITATIONS = 51;
159159 public static final String CREATE_LOBBY_TOO_MANY_INVITATIONS_STR = "Too many invitations";
160+
161+ public static final int CREATE_SERVER_ALREADY_EXISTS = 52;
162+ public static final String CREATE_SERVER_ALREADY_EXISTS_STR = "Server has been already registered";
163+
164+ public static final int CREATE_SERVER_CANNOT_FIND_SERVER_ID = 53;
165+ public static final String CREATE_SERVER_CANNOT_FIND_SERVER_ID_STR = "Cannot find server id";
160166 }
diff -r 3108183fea89 -r ffe267892920 src/headwayEnt/headwayEnt/Blackhole_Darksun_WebServer/Main.java
--- a/src/headwayEnt/headwayEnt/Blackhole_Darksun_WebServer/Main.java Tue Jan 15 22:50:18 2019 +0200
+++ b/src/headwayEnt/headwayEnt/Blackhole_Darksun_WebServer/Main.java Wed Jan 16 22:33:19 2019 +0200
@@ -707,19 +707,45 @@
707707 @Produces({"application/json", "text/plain"})
708708 public Response createServer(@Context HttpServletRequest requestContext, Server server) {
709709 String clientIP = requestContext.getRemoteAddr();
710- List<Server> serverList = em.createNamedQuery(Server.GET_SERVER_BY_NAME_AND_IP)
711- .setParameter("serverName", server.getServerName())
712- .setParameter("serverIp", server.getIp())
713- .getResultList();
714-// if (!serverList.isEmpty()) {
715-// server.setError("Server name already exists");
716-// return createResponse(server);
710+ // We get the actual ip not the one that might be from the local DHCP of the server.
711+ server.setIp(clientIP);
712+ if (server.getId() == 0) {
713+ // This is a new server. Still check if it was just a reinstallation.
714+ List<Server> serverList = em.createNamedQuery(Server.GET_SERVER_BY_NAME_AND_IP)
715+ .setParameter("serverName", server.getServerName())
716+ .setParameter("serverIp", server.getIp())
717+ .getResultList();
718+ if (serverList.size() > 1) {
719+ server.setErrorCode(ErrorCodes.CREATE_SERVER_ALREADY_EXISTS);
720+ server.setError(ErrorCodes.CREATE_SERVER_ALREADY_EXISTS_STR);
721+ return createResponse(server);
722+ } else if (serverList.size() == 1) {
723+ // Renew the id.
724+ server.setId(serverList.get(0).getId());
725+ return createResponse(server);
726+ } else {
727+ em.persist(server);
728+ em.flush();
729+ return createResponse(server);
730+ }
731+ } else {
732+ final List<Server> serverList = em.createNamedQuery(Server.GET_SERVER_BY_ID)
733+ .setParameter("serverId", server.getId()).getResultList();
734+ if (serverList.isEmpty()) {
735+ server.setErrorCode(ErrorCodes.CREATE_SERVER_CANNOT_FIND_SERVER_ID);
736+ server.setError(ErrorCodes.CREATE_SERVER_CANNOT_FIND_SERVER_ID_STR);
737+ return createResponse(server);
738+ }
739+ final Server selectedServer = serverList.get(0);
740+ // Check that the server is the same with the one from the database?
741+ return createResponse(server);
742+ }
743+
744+
745+// if (serverList.isEmpty()) {
746+// em.persist(server);
717747 // }
718- server.setIp(clientIP);
719- if (serverList.isEmpty()) {
720- em.persist(server);
721- }
722- return createResponse(server);
748+// return createResponse(server);
723749 }
724750
725751 @POST
diff -r 3108183fea89 -r ffe267892920 src/test/java/Blackhole_Darksun_WebServer/MainTest.java
--- a/src/test/java/Blackhole_Darksun_WebServer/MainTest.java Tue Jan 15 22:50:18 2019 +0200
+++ b/src/test/java/Blackhole_Darksun_WebServer/MainTest.java Wed Jan 16 22:33:19 2019 +0200
@@ -322,7 +322,7 @@
322322 public void testCreateServer() throws Exception {
323323 Server server = new Server();
324324 server.setServerName("mainServer");
325-// server.setIp("127.0.0.1");
325+ server.setIp("127.0.0.1");
326326 server.setServerLoad(0);
327327 server.setSessionNum(0);
328328 server.setUserNum(0);