/** * Handles the move put from a Client. * * @param params is a String array containing the blocks to place */ public void doMovePut(String[] params) { Map<Point, Block> moves = new HashMap<>(); for (String move : params) { String[] moveArg = move.split("@"); int blockId = Integer.parseInt(moveArg[0]); int moveX = Integer.parseInt(moveArg[1].split(",")[0]); int moveY = Integer.parseInt(moveArg[1].split(",")[1]); moves.put(new Point(moveX, moveY), new Block(blockId)); } try { game.doMovePut(moves); System.out.println("[Server] (ClientHandler) - Current game situation:"); System.out.println(game.getBoard().toString()); } catch (InvalidMoveException e) { sendError(IProtocol.Error.MOVE_INVALID.ordinal() + " Invalid move"); game.sendPlayerTurn(); } catch (TilesUnownedException e) { sendError( IProtocol.Error.MOVE_TILES_UNOWNED.ordinal() + " Player tried to place unowned tile"); game.sendPlayerTurn(); } catch (NullPointerException e) { System.out.println("[Server] ClientHandler - Game ended during turn."); } }
public static void SP_trigger_key(Entity self) { if (GameBase.st.item == null) { ServerGame.PF_dprintf("no key item for trigger_key at " + Lib.vtos(self.s.origin) + "\n"); return; } self.item = GameItems.FindItemByClassname(GameBase.st.item); if (null == self.item) { ServerGame.PF_dprintf( "item " + GameBase.st.item + " not found for trigger_key at " + Lib.vtos(self.s.origin) + "\n"); return; } if (self.target == null) { ServerGame.PF_dprintf(self.classname + " at " + Lib.vtos(self.s.origin) + " has no target\n"); return; } ServerInit.SV_SoundIndex("misc/keytry.wav"); ServerInit.SV_SoundIndex("misc/keyuse.wav"); self.use = trigger_key_use; }
public void use(Entity self, Entity other, Entity activator) { if (self.count == 0) return; self.count--; if (self.count != 0) { if (0 == (self.spawnflags & 1)) { ServerGame.PF_centerprintf(activator, self.count + " more to go..."); ServerGame.PF_StartSound( activator, Constants.CHAN_AUTO, ServerInit.SV_SoundIndex("misc/talk1.wav"), (float) 1, (float) Constants.ATTN_NORM, (float) 0); } return; } if (0 == (self.spawnflags & 1)) { ServerGame.PF_centerprintf(activator, "Sequence completed!"); ServerGame.PF_StartSound( activator, Constants.CHAN_AUTO, ServerInit.SV_SoundIndex("misc/talk1.wav"), (float) 1, (float) Constants.ATTN_NORM, (float) 0); } self.activator = activator; multi_trigger(self); }
public static void SP_trigger_multiple(Entity ent) { if (ent.sounds == 1) ent.noise_index = ServerInit.SV_SoundIndex("misc/secret.wav"); else if (ent.sounds == 2) ent.noise_index = ServerInit.SV_SoundIndex("misc/talk.wav"); else if (ent.sounds == 3) ent.noise_index = ServerInit.SV_SoundIndex("misc/trigger1.wav"); if (ent.wait == 0) ent.wait = 0.2f; ent.touch = Touch_Multi; ent.movetype = Constants.MOVETYPE_NONE; ent.svflags |= Constants.SVF_NOCLIENT; if ((ent.spawnflags & 4) != 0) { ent.solid = Constants.SOLID_NOT; ent.use = trigger_enable; } else { ent.solid = Constants.SOLID_TRIGGER; ent.use = Use_Multi; } if (!Math3D.VectorEquals(ent.s.angles, Globals.vec3_origin)) GameBase.G_SetMovedir(ent.s.angles, ent.movedir); ServerGame.PF_setmodel(ent, ent.model); World.SV_LinkEdict(ent); }
public void touch(Entity self, Entity other, Plane plane, Surface surf) { int dflags; if (other.takedamage == 0) return; if (self.timestamp > GameBase.level.time) return; if ((self.spawnflags & 16) != 0) self.timestamp = GameBase.level.time + 1; else self.timestamp = GameBase.level.time + Constants.FRAMETIME; if (0 == (self.spawnflags & 4)) { if ((GameBase.level.framenum % 10) == 0) ServerGame.PF_StartSound( other, Constants.CHAN_AUTO, self.noise_index, (float) 1, (float) Constants.ATTN_NORM, (float) 0); } if ((self.spawnflags & 8) != 0) dflags = Constants.DAMAGE_NO_PROTECTION; else dflags = 0; GameCombat.T_Damage( other, self, self, Globals.vec3_origin, other.s.origin, Globals.vec3_origin, self.dmg, self.dmg, dflags, Constants.MOD_TRIGGER_HURT); }
public static void InitTrigger(Entity self) { if (!Math3D.VectorEquals(self.s.angles, Globals.vec3_origin)) GameBase.G_SetMovedir(self.s.angles, self.movedir); self.solid = Constants.SOLID_TRIGGER; self.movetype = Constants.MOVETYPE_NONE; ServerGame.PF_setmodel(self, self.model); self.svflags = Constants.SVF_NOCLIENT; }
public void startGame() { flyCam.setEnabled(true); flyCam.setMoveSpeed(25f); inputManager.setCursorVisible(true); enqueue( () -> { game.start(); return null; }); }
public static void SP_trigger_gravity(Entity self) { if (GameBase.st.gravity == null) { ServerGame.PF_dprintf( "trigger_gravity without gravity set at " + Lib.vtos(self.s.origin) + "\n"); GameUtil.G_FreeEdict(self); return; } InitTrigger(self); self.gravity = Lib.atoi(GameBase.st.gravity); self.touch = trigger_gravity_touch; }
/** * Handles the trade from a Client. * * @param params is a String array containing the blocks to trade */ public void doMoveTrade(String[] params) { List<Block> tradeBlocks = new ArrayList<>(); for (String block : params) { tradeBlocks.add(new Block(Integer.parseInt(block))); } try { game.doMoveTrade(tradeBlocks); } catch (TradeFirstTurnException e) { sendError(IProtocol.Error.TRADE_FIRST_TURN.ordinal() + " You cannot trade on the first turn"); game.sendPlayerTurn(); } catch (TilesUnownedException e) { sendError( IProtocol.Error.MOVE_TILES_UNOWNED.ordinal() + " Player tried to place unowned tile"); game.sendPlayerTurn(); } catch (EmptyBagException e) { sendError( IProtocol.Error.DECK_EMPTY.ordinal() + " The bag does not contain this many blocks"); game.sendPlayerTurn(); } }
public static Entity G_PickTarget(String targetname) { int num_choices = 0; Entity choice[] = new Entity[MAXCHOICES]; if (targetname == null) { ServerGame.PF_dprintf("G_PickTarget called with null targetname\n"); return null; } EntityIterator es = null; while ((es = G_Find(es, findByTarget, targetname)) != null) { choice[num_choices++] = es.o; if (num_choices == MAXCHOICES) break; } if (num_choices == 0) { ServerGame.PF_dprintf("G_PickTarget: target " + targetname + " not found\n"); return null; } return choice[Lib.rand() % num_choices]; }
/** Safely disconnects this ClientHandler from the Server */ public void disconnect() { try { pool.removeFromAllQueues(this); if (game != null) { game.endGame(false); // End the game the client was in. } reader.close(); writer.close(); client.close(); System.out.println("[Server] Debug (ClientHandler) - Client has disconnected."); pool.removeClient(name); connected = false; } catch (IOException e) { e.printStackTrace(); } }
/** * QUAKED trigger_once (.5 .5 .5) ? x x TRIGGERED Triggers once, then removes itself. You must set * the key "target" to the name of another object in the level that has a matching "targetname". * * <p>If TRIGGERED, this trigger must be triggered before it is live. * * <p>sounds 1) secret 2) beep beep 3) large switch 4) * * <p>"message" string to be displayed when triggered */ public static void SP_trigger_once(Entity ent) { // make old maps work because I messed up on flag assignments here // triggered was on bit 1 when it should have been on bit 4 if ((ent.spawnflags & 1) != 0) { float[] v = {0, 0, 0}; Math3D.VectorMA(ent.mins, 0.5f, ent.size, v); ent.spawnflags &= ~1; ent.spawnflags |= 4; ServerGame.PF_dprintf( "fixed TRIGGERED flag on " + ent.classname + " at " + Lib.vtos(v) + "\n"); } ent.wait = -1; SP_trigger_multiple(ent); }
public void touch(Entity self, Entity other, Plane plane, Surface surf) { if (Lib.strcmp(other.classname, "grenade") == 0) { Math3D.VectorScale(self.movedir, self.speed * 10, other.velocity); } else if (other.health > 0) { Math3D.VectorScale(self.movedir, self.speed * 10, other.velocity); if (other.client != null) { // don't take falling damage immediately from this Math3D.VectorCopy(other.velocity, other.client.oldvelocity); if (other.fly_sound_debounce_time < GameBase.level.time) { other.fly_sound_debounce_time = GameBase.level.time + 1.5f; ServerGame.PF_StartSound( other, Constants.CHAN_AUTO, windsound, (float) 1, (float) Constants.ATTN_NORM, (float) 0); } } } if ((self.spawnflags & PUSH_ONCE) != 0) GameUtil.G_FreeEdict(self); }
/** * parses a message * * @param message is a String array */ public void parse(String[] message) { switch (message[0]) { case IProtocol.CLIENT_IDENTIFY: if (message.length < 1) { break; } String userName = message[1]; try { pool.addClient(name, this); name = userName; sendRaw(IProtocol.SERVER_IDENTIFY); } catch (InvalidNameException e) { sendError(IProtocol.Error.NAME_INVALID.ordinal() + " Invalid name"); } catch (UsedNameException e) { sendError(IProtocol.Error.NAME_USED.ordinal() + " Name is already in use"); } break; case IProtocol.CLIENT_QUIT: disconnect(); break; case IProtocol.CLIENT_MOVE_PUT: if (game == null) { break; } if (game.getTurnClient().equals(this)) { doMovePut(Arrays.copyOfRange(message, 1, message.length)); } else { sendError(IProtocol.Error.ILLEGAL_STATE.ordinal() + " It is not your turn"); } break; case IProtocol.CLIENT_MOVE_TRADE: if (game == null) { break; } if (game.getTurnClient().equals(this)) { doMoveTrade(Arrays.copyOfRange(message, 1, message.length)); } else { sendError(IProtocol.Error.ILLEGAL_STATE.ordinal() + " It is not your turn"); } break; case IProtocol.CLIENT_QUEUE: if (message.length < 1) { break; } else if (game != null) { sendError( IProtocol.Error.ILLEGAL_STATE.ordinal() + " You cannot queue while you are in a game"); break; } String[] queues = message[1].split(","); try { for (String queue : queues) { try { int queueSize = Integer.parseInt(queue); pool.addClientToQueue(this, queueSize); } catch (NumberFormatException e) { System.out.println("Player tried to join invalid queue."); } } sendRaw(IProtocol.SERVER_QUEUE); } catch (NumberFormatException e) { sendRaw(String.valueOf(IProtocol.Error.QUEUE_INVALID)); } break; default: sendRaw( String.valueOf( IProtocol.Error.INVALID_COMMAND.ordinal() + " The server does not recognise this command")); break; } }
public void use(Entity self, Entity other, Entity activator) { int index; if (self.item == null) return; if (activator.client == null) return; index = GameItems.ITEM_INDEX(self.item); if (activator.client.pers.inventory[index] == 0) { if (GameBase.level.time < self.touch_debounce_time) return; self.touch_debounce_time = GameBase.level.time + 5.0f; ServerGame.PF_centerprintf(activator, "You need the " + self.item.pickup_name); ServerGame.PF_StartSound( activator, Constants.CHAN_AUTO, ServerInit.SV_SoundIndex("misc/keytry.wav"), (float) 1, (float) Constants.ATTN_NORM, (float) 0); return; } ServerGame.PF_StartSound( activator, Constants.CHAN_AUTO, ServerInit.SV_SoundIndex("misc/keyuse.wav"), (float) 1, (float) Constants.ATTN_NORM, (float) 0); if (GameBase.coop.value != 0) { int player; Entity ent; if (Lib.strcmp(self.item.classname, "key_power_cube") == 0) { int cube; for (cube = 0; cube < 8; cube++) if ((activator.client.pers.power_cubes & (1 << cube)) != 0) break; for (player = 1; player <= GameBase.game.maxclients; player++) { ent = GameBase.g_edicts[player]; if (!ent.inuse) continue; if (null == ent.client) continue; if ((ent.client.pers.power_cubes & (1 << cube)) != 0) { ent.client.pers.inventory[index]--; ent.client.pers.power_cubes &= ~(1 << cube); } } } else { for (player = 1; player <= GameBase.game.maxclients; player++) { ent = GameBase.g_edicts[player]; if (!ent.inuse) continue; if (ent.client == null) continue; ent.client.pers.inventory[index] = 0; } } } else { activator.client.pers.inventory[index]--; } GameUtil.G_UseTargets(self, activator); self.use = null; }
public static void ShutdownGame() { ServerGame.PF_dprintf("==== ShutdownGame ====\n"); }