Adds connection and disconnection callbacks for all players
Not only for own player
This commit is contained in:
@ -7,7 +7,7 @@ namespace CoopClient
|
||||
public static class Interface
|
||||
{
|
||||
#region DELEGATES
|
||||
public delegate void ConnectEvent(bool connected, string reason = null);
|
||||
public delegate void ConnectEvent(bool connected, long fromId, string reason = null);
|
||||
public delegate void ChatMessage(string from, string message, CancelEventArgs args);
|
||||
public delegate void ModEvent(long from, string mod, byte customID, byte[] bytes);
|
||||
#endregion
|
||||
@ -19,12 +19,22 @@ namespace CoopClient
|
||||
|
||||
internal static void Connected()
|
||||
{
|
||||
OnConnection?.Invoke(true);
|
||||
OnConnection?.Invoke(true, GetLocalID());
|
||||
}
|
||||
|
||||
internal static void Disconnected(string reason)
|
||||
{
|
||||
OnConnection?.Invoke(false, reason);
|
||||
OnConnection?.Invoke(false, GetLocalID(), reason);
|
||||
}
|
||||
|
||||
internal static void Connected(long userId)
|
||||
{
|
||||
OnConnection?.Invoke(true, userId);
|
||||
}
|
||||
|
||||
internal static void Disconnected(long userId)
|
||||
{
|
||||
OnConnection?.Invoke(false, userId);
|
||||
}
|
||||
|
||||
internal static void ModPacketReceived(long from, string mod, byte customID, byte[] bytes)
|
||||
@ -78,6 +88,14 @@ namespace CoopClient
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Entities.EntitiesPlayer GetPlayer( long playerId )
|
||||
{
|
||||
if (Main.Players.ContainsKey(playerId))
|
||||
return Main.Players[playerId];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool IsMenuVisible()
|
||||
{
|
||||
#if NON_INTERACTIVE
|
||||
|
@ -46,6 +46,11 @@ namespace CoopClient
|
||||
|
||||
string[] ip = address.Split(':');
|
||||
|
||||
if(ip.Length != 2)
|
||||
{
|
||||
throw new Exception("Malformed URL");
|
||||
}
|
||||
|
||||
// Send HandshakePacket
|
||||
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
||||
new HandshakePacket()
|
||||
@ -260,6 +265,7 @@ namespace CoopClient
|
||||
};
|
||||
|
||||
Main.Players.Add(packet.ID, player);
|
||||
Interface.Connected(packet.ID);
|
||||
}
|
||||
|
||||
private void PlayerDisconnect(PlayerDisconnectPacket packet)
|
||||
@ -275,6 +281,7 @@ namespace CoopClient
|
||||
|
||||
player.PedBlip?.Delete();
|
||||
|
||||
Interface.Disconnected(packet.ID);
|
||||
Main.Players.Remove(packet.ID);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user