Skip to content

Commit

Permalink
Added messages design doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Nov 12, 2020
1 parent 790d57a commit 5f06305
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
12 changes: 12 additions & 0 deletions docs/design/communication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Communication

The following diagram shows the protocol communication used between client and server:

Notes:
- Orange arrows show UDP messages,
- Purple arrows show preferred UDP messages.
- Default color arrows show TCP messages.

<p align="center">
<img src="http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/lemunozm/asciiarena/master/docs/design/diagrams/messages.puml"/>
</p>
59 changes: 59 additions & 0 deletions docs/design/diagrams/messages.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@startuml

' Orange color represents an UDP message
' Purple color represents a prefered UDP message
' Default color represents TCP message

title Client - Server communication protocol

participant Client
participant Server

== Initialization ==
Client -> Server : Version
Client <-- Server : Version

== Server information subscription ==
Client -> Server : SubscribeServerInfo
Client <-- Server : ServerInfo
group Any change in the server: e.g: a player login/logout
Client <<- Server : DynamicServerInfo
end

== Login/Logout ==
Client -> Server : Login
Client <-- Server : LoginStatus
group If logged successful:
loop while not received UdpConnected, max 10
Client -[#orange]> Server : ConnectUdp
Client <[#orange]-- Server : UdpConnected
end
group If received UdpConnected:
Client -> Server : TrustUdp
end
end
...
Client -> Server : Logout

== Game/Arena system ==
Client <- Server : StartGame
loop there is not a game winner
Client <- Server : PrepareArena
...
Client <- Server : StartArena
note over Client, Server
Arena round
end note
Client <- Server : EndArena
end

== Arena round ==
loop each frame until there is an arena winner
group any of the following player actions:
Client ->> Server : MovePlayer
Client ->> Server : CastSkill
end
Client <[#purple]- Server : Step
end

@enduml
6 changes: 4 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use serde::{Serialize, Deserialize};

use std::time::{Duration};

// See the protocol diagram in docs/design/communication.md

// ===================================================
// High level messages
// ===================================================
Expand All @@ -24,8 +26,8 @@ pub enum ClientMessage {
TrustUdp,

// Arena real time messages
Move, //direction
Skill, //id
MovePlayer, //direction
CastSkill, //id
}

/// Messages that Server sends to Client
Expand Down
4 changes: 2 additions & 2 deletions src/server/server_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ impl ServerManager {
ClientMessage::TrustUdp => {
self.process_trust_udp(endpoint);
},
ClientMessage::Move => {
ClientMessage::MovePlayer => {
//TODO
},
ClientMessage::Skill => {
ClientMessage::CastSkill => {
//TODO
},
}
Expand Down

0 comments on commit 5f06305

Please sign in to comment.