superpowers

Co-authored-by: GM <giulio.migani@studenti.unitn.it>
This commit is contained in:
Alberto Xamin 2021-06-19 16:46:50 +02:00
parent 1ac37f9039
commit 413f3ae54b
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
4 changed files with 115 additions and 7 deletions

View File

@ -15,6 +15,8 @@ sio = socketio.Server(cors_allowed_origins="*")
static_files={
'/': {'content_type': 'text/html', 'filename': 'index.html'},
'/game': {'content_type': 'text/html', 'filename': 'index.html'},
'/help': {'content_type': 'text/html', 'filename': 'index.html'},
'/status': {'content_type': 'text/html', 'filename': 'index.html'},
# '/robots.txt': {'content_type': 'text/html', 'filename': 'robots.txt'},
'/favicon.ico': {'filename': 'favicon.ico'},
'/img/icons': './img/icons',
@ -31,7 +33,7 @@ games: List[Game] = []
online_players = 0
def advertise_lobbies():
sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if not g.started and len(g.players) < 10 and not g.is_hidden])
sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'password': g.password} for g in games if not g.started and len(g.players) < 10 and not g.is_hidden])
sio.emit('spectate_lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if g.started])
@sio.event
@ -253,11 +255,6 @@ def chat_message(sid, msg):
eventlet.sleep(0.3)
else:
sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} bad format'})
elif '/hide' in msg:
cmd = msg.split()
ses.game.is_hidden = not ses.game.is_hidden
advertise_lobbies()
sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} room hidden: {ses.game.is_hidden}'})
elif '/ddc' in msg and ses.game.started: # debug destroy cards usage: [/ddc *] [/ddc username]
cmd = msg.split()
if len(cmd) == 2:
@ -362,6 +359,35 @@ def chat_message(sid, msg):
color = sid.encode('utf-8').hex()[-3:]
sio.emit('chat_message', room=ses.game.name, data={'color': f'#{color}','text':f'[{ses.name}]: {msg}'})
@sio.event
def get_all_rooms(sid, deploy_key):
if 'DEPLOY_KEY' in os.environ and deploy_key == os.environ['DEPLOY_KEY']:
sio.emit('all_rooms', room=sid, data=[{
'name': g.name,
'hidden': g.is_hidden,
'players': [{'name':p.name, 'bot': p.is_bot, 'health': p.lives, 'sid': p.sid} for p in g.players],
'password': g.password,
'expansions': g.expansions,
'started': g.started,
'current_turn': g.turn,
'incremental_turn': g.incremental_turn,
'debug': g.debug,
'spectators': len(g.spectators)
} for g in games])
@sio.event
def kick(sid, data):
if 'DEPLOY_KEY' in os.environ and data['key'] == os.environ['DEPLOY_KEY']:
sio.emit('kicked', room=data['sid'])
@sio.event
def hide_toogle(sid, data):
if 'DEPLOY_KEY' in os.environ and data['key'] == os.environ['DEPLOY_KEY']:
game = [g for g in games if g.name==data['room']]
if len(games) > 0:
game[0].is_hidden = not game[0].is_hidden
advertise_lobbies()
@sio.event
def start_game(sid):
ses: Player = sio.get_session(sid)

View File

@ -182,6 +182,10 @@ export default {
change_username() {
this.hasToSetUsername = true
},
kicked() {
window.location.replace(window.location.origin)
document.title = 'PewPew!'
},
},
computed: {
inviteLink() {

View File

@ -0,0 +1,73 @@
<template>
<div>
<h1 id="status">PewPew! Server Status</h1>
<h2>Rooms {{rooms.length}}</h2>
<button @click="refresh">reload</button>
<ul>
<li v-for="r in rooms" :key="r">
<p style="margin:0"><b>name:</b> {{r.name}}</p>
<p style="margin:0"><b>hidden:</b> {{r.hidden}}</p>
<button @click="hide(r.name)">toggle hide</button>
<p style="margin:0"><b>password:</b> {{r.password}}</p>
<p style="margin:0"><b>mods:</b> {{r.expansions}}</p>
<p style="margin:0"><b>started:</b> {{r.started}}</p>
<p style="margin:0"><b>turn:</b> {{r.current_turn}}</p>
<p style="margin:0"><b>incremental_turn:</b> {{r.incremental_turn}}</p>
<p style="margin:0"><b>debug:</b> {{r.debug}}</p>
<p style="margin:0"><b>spectators:</b> {{r.spectators}}</p>
<p style="margin:0"><b>players:</b></p>
<ul style="margin:0">
<li v-for="p in r.players" :key="p">
<p style="margin:0"><b>name:</b> {{p.name}}</p>
<p style="margin:0"><b>is_bot:</b> {{p.is_bot}}</p>
<p style="margin:0"><b>health:</b> {{p.health}}</p>
<button @click="kick(p.sid)">Kick</button>
</li>
</ul>
<br>
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'Help',
components: {
},
data:()=>({
rooms: [],
deploy_key: ''
}),
computed: {
},
sockets: {
all_rooms(data) {
this.rooms = data;
},
},
mounted() {
if (this.deploy_key == "")
this.deploy_key = prompt('Write the key');
this.refresh();
},
methods: {
refresh(){
this.$socket.emit('get_all_rooms', this.deploy_key)
},
hide(room_name){
this.$socket.emit('hide_toogle', {'key':this.deploy_key, 'room':room_name})
setTimeout((()=>{
this.refresh()
}).bind(this), 200)
},
kick(sid){
this.$socket.emit('kick', {'key':this.deploy_key, 'sid':sid})
setTimeout((()=>{
this.refresh()
}).bind(this), 200)
}
}
}
</script>
<style scoped>
</style>

View File

@ -12,7 +12,12 @@ const routes = [
{
path: '/help',
name: 'Help',
component: () => import(/* webpackChunkName: "helep" */ '../components/Help.vue')
component: () => import(/* webpackChunkName: "help" */ '../components/Help.vue')
},
{
path: '/status',
name: 'Status',
component: () => import(/* webpackChunkName: "status" */ '../components/Status.vue')
},
{
path: '/',