-
Notifications
You must be signed in to change notification settings - Fork 1
Websocket interaction
In order to connect to Bomberman-server via webswocket connect to GET ws://tekhno-bomberman.tk/game
with correct authentication cookie. You can check whether you are authenticated by accessing GET http://tekhno-bomberman.tk/api/session
.
JSON messages with following structure are sent via websocket:
{
type: "<message_type>",
[additional fields]
}
Message protocol is JSON, specified at json.org.
-
object_spawned
↓ -- sent by server to client. Used to notify client if a new entity on map had been spawned (either during gameplay: things like bombs and bombs' rays or during world creation when undestructible and destructible walls are stationed). -
bomberman_spawned
↓ -- sent by server to client. Used to notify client when bombermen are stationed. -
object_destroyed
↓ -- sent by server to client. Used to notify client if an existing entity had been destroyed (e.g. bomberman has died, bonus has been picked up or wall has been destroyed). -
user_joined
↓ -- sent by server to client. Used to notify another side if user has joined. -
user_left
↓ -- sent by server to client. Used to notify another side if user has joined, has pressed "ready" button, has decided to quit the game, etc. -
game_over
↓ -- sent by server when only one bomberman is still alive. Or zero bombermen. -
world_created
↓ -- sent by server when all clients have pressed "ready" button and have content loaded. Should probably encourage clients to remove loading screen.
-
object_changed
↓ -- sent by server to client or by client to server. Used to notify another side if bomberman has moved. (Or its parameters has been changed -- not used) -
user_state_changed
↓ -- sent by server to client or by client to server. Used to notify another side if user has pressed "ready" button or initiated another action. -
chat_message
↓ -- sent by server to client or by client to server. Used to notify another side if a new room chat message is sent. Not used!
-
bomb_spawned
↓ -- sent by client when player attempts to place a bomb. -
ping
↓ -- sent by client every second to confirm he is still connected.
##object_spawned
-
id
-- unique object identifier. -
object_type
-- type of instantiated object. Can beundestructible_wall
,destructible_wall
,bonus_decrease_bomb_explosion_delay
,bonus_decrease_bomb_spawn_delay
,bonus_increase_bomb_range
,bomb
,bomb_ray
. -
x
andy
are coordinates in range[0..width]
and[0..height]
.width
andheight
are usually 32 by 32, but can be different. Refer toworld_created
event.
{
type: "object_spawned",
id: 0,
object_type: "object_type",
x: 0,
y: 0
}
##bomberman_spawned
-
id
-- unique object identifier. -
user_id
-- ID of user this bomberman belongs to.. -
x
andy
are coordinates in range[0..width]
and[0..height]
.width
andheight
are usually 32 by 32, but can be different. Refer toworld_created
event.
{
type: "bomberman_spawned",
id: 5,
user_id: 430,
x: 0,
y: 0
}
##object_destroyed
-
id
-- unique object identifier.
{
type: "object_destroyed",
id: 0
}
##object_changed Client should send infromation once user is began or stopped holding movement down.
-
id
-- unique object identifier. If message is sent by server, this is an id of one of four bombermen. -
x
andy
are coordinates in range[0..width]
and[0..height]
.width
andheight
are usually 32 by 32, but can be different. Refer toworld_created
event.
{
type: "object_changed",
id: 0,
x: 0.5,
y: 31.333333
}
##user_joined
-
id
-- unique user identifier. -
isReady
-- specifies if user is ready to start game. -
contentLoaded
-- specifies if has models and textures loaded and has positioned tiles. -
name
-- specifies shown name. Currently similar to login. -
score
-- user score. Updated after every game, so don't bother refreshing it. :) -
userpic_path
-- specifies path to userpic. Can benull
!
{
type: "user_joined",
id: 0,
isReady: false,
contentLoaded: false
name: "User номер I",
score: 9999,
userpic_path: "/static/userpic/0.png"
}
##user_state_changed
-
isReady
-- specifies if user is ready to start game. -
contentLoaded
-- marks if all textures and models are loaded. When all users have this flag, world details will be transmitted to everyone. -
id
-- id of player whom state has changed.
{
type: "user_state_changed",
isReady: true,
contentLoaded: false,
id: 123
}
##user_left
-
id
-- unique user identifier.
{
type: "user_left",
id: 0
}
##chat_message
-
user_id
-- unique user identifier. -
text
-- message text. Can contain escape sequence symbols.
{
type: "chat_message",
user_id: 0,
text: "aasdadasd\nsasdad"
}
##game_over
-
winner
-- contains unique user identifier ornull
in draft case.
{
type: "game_over",
winner: 369
}
##world_created
-
title
-- world's name. -
width
-- world's width. (In tiles) -
height
-- world's height.
{
type: "world_created",
title: "Spiral world",
width: 32,
height: 32
}
##bomb_spawned Client should send this once player hits "Spacebar".
{
type: "bomb_spawned"
}
##ping Client should send this every second or two to minimize risk of being disconnected on timeout.
{
type: "ping"
}