import {getShopEquipment, listShopItems } from './shopEquipment';
import {EquipmentSlot} from '../shared/inventory';
import { clearTravelPlan, completeTravel, getAllPaths, getAllServices, getCityDetails, getService, getTravelPlan, stepForward, travel } from './map';
-import { signup, login, authEndpoint, AuthRequest } from './auth';
+import { signup, login, authEndpoint } from './auth';
import {db} from './lib/db';
import { getPlayerSkills} from './skills';
app.use(repairRouter);
-app.get('/chat/history', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/chat/history', authEndpoint, async (req: Request, res: Response) => {
let html = chatHistory.map(renderChatMessage);
res.send(html.join("\n"));
});
-app.post('/chat', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/chat', authEndpoint, async (req: Request, res: Response) => {
const msg = req.body.message.trim();
if(!msg || !msg.length) {
}
});
-app.get('/player', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/player', authEndpoint, async (req: Request, res: Response) => {
const equipment = await getEquippedItems(req.player.id);
res.send(renderPlayerBar(req.player) + renderProfilePage(req.player, equipment));
});
-app.post('/player/stat/:stat', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/player/stat/:stat', authEndpoint, async (req: Request, res: Response) => {
const equipment = await getEquippedItems(req.player.id);
const stat = req.params.stat;
if(!['strength', 'constitution', 'dexterity', 'intelligence'].includes(stat)) {
res.send(renderPlayerBar(req.player) + renderProfilePage(req.player, equipment));
});
-app.get('/player/skills', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/player/skills', authEndpoint, async (req: Request, res: Response) => {
const skills = await getPlayerSkills(req.player.id);
res.send(renderSkills(skills));
});
-app.get('/player/inventory', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/player/inventory', authEndpoint, async (req: Request, res: Response) => {
const [inventory, items] = await Promise.all([
getInventory(req.player.id),
getPlayersItems(req.player.id)
res.send(renderInventoryPage(inventory, items));
});
-app.post('/player/equip/:item_id/:slot', authEndpoint, blockPlayerInFight, async (req: AuthRequest, res: Response) => {
+app.post('/player/equip/:item_id/:slot', authEndpoint, blockPlayerInFight, async (req: Request, res: Response) => {
const inventoryItem = await getInventoryItem(req.player.id, req.params.item_id);
const equippedItems = await getEquippedItems(req.player.id);
const requestedSlot = req.params.slot;
res.send(renderInventoryPage(inventory, items, inventoryItem.type) + renderPlayerBar(req.player));
});
-app.post('/player/unequip/:item_id', authEndpoint, blockPlayerInFight, async (req: AuthRequest, res: Response) => {
+app.post('/player/unequip/:item_id', authEndpoint, blockPlayerInFight, async (req: Request, res: Response) => {
const [item, ] = await Promise.all([
getInventoryItem(req.player.id, req.params.item_id),
unequip(req.player.id, req.params.item_id)
res.send(renderInventoryPage(inventory, items, item.type) + renderPlayerBar(req.player));
});
-app.get('/player/explore', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/player/explore', authEndpoint, async (req: Request, res: Response) => {
const fight = await loadMonsterFromFight(req.player.id);
const travelPlan = await getTravelPlan(req.player.id);
let closestTown = req.player.city_id;
});
// used to purchase equipment from a particular shop
-app.put('/location/:location_id/equipment/:item_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.put('/location/:location_id/equipment/:item_id', authEndpoint, async (req: Request, res: Response) => {
const item = await getShopEquipment(parseInt(req.params.item_id), parseInt(req.params.location_id));
if(!item) {
});
// used to purchase items from a particular shop
-app.put('/location/:location_id/items/:item_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.put('/location/:location_id/items/:item_id', authEndpoint, async (req: Request, res: Response) => {
const item: (ShopItem & Item) = await getItemFromShop(parseInt(req.params.item_id), parseInt(req.params.location_id));
if(!item) {
// used to display equipment modals in a store, validates that
// the equipment is actually in this store before displaying
// the modal
-app.get('/location/:location_id/equipment/:item_id/overview', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/location/:location_id/equipment/:item_id/overview', authEndpoint, async (req: Request, res: Response) => {
const equipment = await getShopEquipment(parseInt(req.params.item_id), parseInt(req.params.location_id));
if(!equipment) {
// used to display item modals in a store, validates that
// the item is actually in this store before displaying
// the modal
-app.get('/location/:location_id/items/:item_id/overview', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/location/:location_id/items/:item_id/overview', authEndpoint, async (req: Request, res: Response) => {
const item: (ShopItem & Item) = await getItemFromShop(parseInt(req.params.item_id), parseInt(req.params.location_id));
if(!item) {
res.send(html);
});
-app.put('/item/:item_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.put('/item/:item_id', authEndpoint, async (req: Request, res: Response) => {
const item: PlayerItem = await getItemFromPlayer(req.player.id, parseInt(req.params.item_id));
if(!item) {
});
-app.get('/modal/items/:item_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/modal/items/:item_id', authEndpoint, async (req: Request, res: Response) => {
const item: PlayerItem = await getItemFromPlayer(req.player.id, parseInt(req.params.item_id));
if(!item) {
res.send(html);
});
-app.get('/city/stores/city:stores/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/city/stores/city:stores/:location_id', authEndpoint, async (req: Request, res: Response) => {
const location = await getService(parseInt(req.params.location_id));
if(!location || location.city_id !== req.player.city_id) {
res.send(html);
});
-app.get('/city/explore/city:explore/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/city/explore/city:explore/:location_id', authEndpoint, async (req: Request, res: Response) => {
const location = await getService(parseInt(req.params.location_id));
if(!location || location.city_id !== req.player.city_id) {
res.send(renderOnlyMonsterSelector(monsters, 0, location));
});
-app.post('/travel', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/travel', authEndpoint, async (req: Request, res: Response) => {
const destination_id = parseInt(req.body.destination_id);
if(!destination_id || isNaN(destination_id)) {
res.json(travelPlan);
});
-app.post('/fight/turn', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/fight/turn', authEndpoint, async (req: Request, res: Response) => {
const fightBlockKey = `fightturn:${req.player.id}`;
if(cache[fightBlockKey] && cache[fightBlockKey] > Date.now()) {
res.send(html + travelSection + playerBar);
});
-app.post('/fight', fightRateLimiter, authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/fight', fightRateLimiter, authEndpoint, async (req: Request, res: Response) => {
if(req.player.hp <= 0) {
logger.log(`Player didn\'t have enough hp`);
return res.sendStatus(400);
res.send(renderFightPreRound(data, true, location, location.city_id));
});
-app.post('/travel/step', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/travel/step', authEndpoint, async (req: Request, res: Response) => {
const stepTimerKey = `step:${req.player.id}`;
const travelPlan = await getTravelPlan(req.player.id);
}
});
-app.post('/travel/return-to-source', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/travel/return-to-source', authEndpoint, async (req: Request, res: Response) => {
// puts the player back in their starting town
// doesn't matter if they don't have one
// redirect them!
});
-app.post('/travel/:destination_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/travel/:destination_id', authEndpoint, async (req: Request, res: Response) => {
if(req.player.hp <= 0) {
logger.log(`Player didn\'t have enough hp`);
res.send(Alert.ErrorAlert('Sorry, you need some HP to start travelling.'));
}));
});
-app.get('/settings', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.get('/settings', authEndpoint, async (req: Request, res: Response) => {
let warning = '';
let html = '';
if(req.player.account_type === 'session') {
res.send(warning + html);
});
-app.post('/logout', authEndpoint, async (req: AuthRequest, res: Response) => {
+app.post('/logout', authEndpoint, async (req: Request, res: Response) => {
// ref to get the socket id for a particular player
cache.delete(`socket:${req.player.id}`);
// ref to get the player object