---
# System prepended metadata

title: Networking
tags: [Jeffistance, Documentation]

---

Networking
===

[TOC]

## Project Structure

- Model-View-ViewModel for the UI
- Shared/Server/Client for everything else
- Shared, Client, and Server are separate projects
  - Shared doesn't include any other projects
  - Server includes the Shared project
  - Client includes the Shared project

```graphviz
digraph hierarchy {

		nodesep=1.0 // increases the separation between nodes
		
		node [color=Purple,fontname=Courier,shape=box] //All nodes will this shape and colour
		edge [color=Blue, style=dashed] //All the lines look like this

        Server->Shared
        Client->Shared
}
```

:::spoiler Example

```csharp
namespace Jeffistance.Shared.Models
{

    public class SharedLobby
    {
        // Data shared by the server and clients
        public List<User> Users { get; set; }
    }
}
```

```csharp
using Jeffistance.Shared.Models;

namespace Jeffistance.Server.Models
{

    public class ServerLobby: SharedLobby
    {
        // Data specific to the server
        private List<User> _readyUsers;
    }
}
```

```csharp
using Jeffistance.Shared.Models;

namespace Jeffistance.Client.Models
{

    public class ClientLobby: SharedLobby
    {
        // Data specific to the client
        private User _currentUser;
    }
}
```

:::

## Flags

### Greeting

```sequence
Title: Greeting
Client->Server: GreetingMessage(User)
Note right of Server: updates own UserList
Server->Server: Broadcast
Note over Server: *for each Client
Server->Client: UpdateMessage(UserList)
```

### Update

```sequence
Title: Update
Server->Client: UpdateMessage(Data)
Note right of Client: Updates AppState with Data
```

### Chat

```sequence
Title: Chat
Client->Server: ChatMessage(Text, UserID)
Note over Server: *for each Client
Server->Client: ChatMessage(Text, UserID)

```

## Networking examples

```sequence
Title: Updating ready users
Client->Server: I just became ready btw
Note over Server: *for each Client
Server->Client: Yo guys he's ready
```

###### tags: `Jeffistance` `Documentation`
