seed_phrase_entropy: u128,
seed_phrase_checksum: u8,
- host: net.TCP_Socket,
+ host: Maybe(net.TCP_Socket),
+ connection_thread: Maybe(^thread.Thread),
}
app_init :: proc(storage_path: string) -> App {
time.sleep(1_000_000)
free_all(context.temp_allocator)
}
+
+ #partial switch app.state {
+ case .Main:
+ {
+ sync.mutex_lock(&app.mutex)
+ defer sync.mutex_unlock(&app.mutex)
+
+ if app.host != nil && app.connection_thread != nil {
+ thread.destroy(app.connection_thread)
+ app.connection_thread = nil
+ }
+ }
+ }
}
}
app_set_state(app, .Connect_To_Host)
}
-state_connect_to_host :: proc(app: ^App) {
- app_set_box_message(
- app,
- {
- "Connecting to host.",
- }
- )
+handle_connection_to_host :: proc(app: ^App) {
+ app_set_info_bar(app, "Connecting to host...")
host_endpoint: net.Endpoint
host_endpoint.port = DEFAULT_PORT
app.host = host
}
+}
+
+state_connect_to_host :: proc(app: ^App) {
+ app_set_box_message(
+ app,
+ {
+ "Connecting to host.",
+ }
+ )
+
+ {
+ sync.mutex_lock(&app.mutex)
+ defer sunc.mutex_unlock(&app.mutex)
+
+ app.connection_thread = thread.create_and_start_with_poly_data(app, handle_connection_to_host, context)
+ }
app_set_state(app, .Main)
}
Public_Key_Bytes :: [32]u8
-Create_Room :: struct {
- room_id: string,
- public: bool,
-}
-
-Kick_User :: struct {
- user_public_key: ed25519.Public_Key,
-}
-
-Ban_User :: struct {
- user_public_key: ed25519.Public_Key,
-}
-
Message :: struct {
room_id: string,
content: string,
}
Client_Request_Content :: union {
- Create_Room,
- Kick_User,
- Ban_User,
-
Message,
}
defer {
log.infof("Client %v disconnected.", client_endpoint_string)
- sync.mutex_lock(clients_sockets_mutex)
- defer sync.mutex_unlock(clients_sockets_mutex)
+ sync.mutex_lock(mutex)
+ defer sync.mutex_unlock(mutex)
delete_key(clients_sockets, client_endpoint)
}
}
server_endpoint := net.Endpoint{
- address = net.IP4_Address{ 127, 0, 0, 1 },
+ address = net.IP4_Address{ 0, 0, 0, 0 },
port = 3000,
}
client_handle_data := Handle_Client_Data{
clients_sockets = &clients_sockets,
- clients_sockets_mutex = &clients_sockets_mutex,
+ mutex = &mutex,
client_socket = client_socket,
client_endpoint = client_endpoint,