Skip to content

Commit

Permalink
feat: Destroy client without disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
avkviring committed Feb 11, 2024
1 parent 6d8d0dc commit 8d06d42
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public byte DestroyClient(ushort clientId)
return FFIMethods.DestroyClient(clientId);
}

public byte DestroyClientWithoutDisconnect(ushort clientId)
{
return FFIMethods.DestroyClientWithoutDisconnect(clientId);
}

public byte AttachToRoom(ushort clientId)
{
return FFIMethods.AttachToRoom(clientId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ out ushort clientId

[DllImport(Library, CallingConvention = CallingConvention.Cdecl, EntryPoint = "destroy_client")]
public static extern byte DestroyClient(ushort clientId);


[DllImport(Library, CallingConvention = CallingConvention.Cdecl, EntryPoint = "destroy_client_without_disconnect")]
public static extern byte DestroyClientWithoutDisconnect(ushort clientId);

[DllImport(dllName: Library, CallingConvention = CallingConvention.Cdecl, EntryPoint = "attach_to_room")]
public static extern byte AttachToRoom(ushort clientId);
Expand Down Expand Up @@ -112,5 +114,8 @@ public static extern byte Set(ushort clientId, in NetworkObjectId objectId, usho
[DllImport(Library, CallingConvention = CallingConvention.Cdecl, EntryPoint = "add_item")]
public static extern byte AddItem(ushort clientId, in NetworkObjectId objectId, ushort fieldIdId,
ref NetworkBuffer buffer);



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public byte DestroyClient(ushort clientId)
return 0;
}

public byte DestroyClientWithoutDisconnect(ushort clientId)
{
return 0;
}

public byte AttachToRoom(ushort clientId)
{
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out ushort clientId
byte GetStatistics(ushort clientId, out Statistics clientStatistics);
unsafe byte Receive(ushort clientId, S2CCommand* commands, ref ushort count);
byte DestroyClient(ushort clientId);
byte DestroyClientWithoutDisconnect(ushort clientId);
byte AttachToRoom(ushort clientId);
byte DetachFromRoom(ushort clientId);
byte SetChannelType(ushort clientId, ReliabilityGuarantees reliabilityGuarantees, byte group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static NetworkClient()
* connectionId
* - идентификатор соединения, изначально 0, если потребуется снова присоединится к данному клиенту на сервере,
* то connectionId должен быть +1 к предыдущему. Данный механизм используется только для переподключения клиента при краше игры.
*
*
*/
public NetworkClient(
ulong connectionId,
Expand Down Expand Up @@ -175,6 +175,14 @@ public void Dispose()
ResultChecker.Check(ffi.DestroyClient(Id));
}

/// <summary>
/// Удалить информацию о текущем клиенте, но не посылать команду Disconnect на сервер
/// </summary>
public void DisposeWithoutDisconnect()
{
ResultChecker.Check(ffi.DestroyClientWithoutDisconnect(Id));
}

/// <summary>
/// Получить серверное время (монотонно возрастающее, отсчет от времени запуска сервера)
/// </summary>
Expand All @@ -199,13 +207,15 @@ public ulong GetServerTimeInMs()
/// <param name="group">группа, для групповых каналов, для остальных игнорируется</param>
public void SetReliabilityGuarantees(ReliabilityGuaranteesChannel reliabilityGuaranteesChannel)
{
if (currentReliabilityGuaranteesChannel != null && currentReliabilityGuaranteesChannel.Equals(reliabilityGuaranteesChannel))
if (currentReliabilityGuaranteesChannel != null &&
currentReliabilityGuaranteesChannel.Equals(reliabilityGuaranteesChannel))
{
return;
}

currentReliabilityGuaranteesChannel = reliabilityGuaranteesChannel;
ResultChecker.Check(ffi.SetChannelType(Id, reliabilityGuaranteesChannel.ReliabilityGuarantees, reliabilityGuaranteesChannel.group));
ResultChecker.Check(ffi.SetChannelType(Id, reliabilityGuaranteesChannel.ReliabilityGuarantees,
reliabilityGuaranteesChannel.group));
}


Expand Down
4 changes: 4 additions & 0 deletions rust/Client/src/clients/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ impl Registry {
}
}
}

pub fn destroy_client_without_disconnect(&mut self, client_id: ClientId) -> Option<ApplicationThreadClient> {
self.clients.remove(&client_id)
}
}
8 changes: 8 additions & 0 deletions rust/Client/src/ffi/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ pub extern "C" fn destroy_client(client: ClientId) -> u8 {
})
}

#[no_mangle]
pub extern "C" fn destroy_client_without_disconnect(client: ClientId) -> u8 {
execute(|registry| match registry.destroy_client_without_disconnect(client) {
None => Err(ClientError::ClientNotFound(client)),
Some(_) => Ok(()),
})
}

#[no_mangle]
pub extern "C" fn receive(client_id: ClientId, out_commands: *mut S2CCommandFFI, count: &mut u16) -> u8 {
execute_with_client(client_id, |client| unsafe {
Expand Down

0 comments on commit 8d06d42

Please sign in to comment.