# FN

## Properties

`Is library initialized or not`

```csharp
public static bool IsInitialized { get; set; }
```

`Read only Configuration instance, it gets populated based on ServerConfig.xml`

```csharp
public static Configuration Settings { get; }
```

`Read only HandlerCollection instance, it is used to Register & UnRegister Handlers`

```csharp
public static HandlerCollection HandlerCollection { get; }
```

`Read only PeerCollection instance, it is used to get connected peers based on type or Id`

```csharp
public static PeerCollection PeerCollection { get; }
```

`Logger instance, we can set it to custom instance, it is used to log debug message to console or file`

```csharp
public static ILogger Logger { get; set; }
```

`Read only List of Open ClientSocket Connection, it used to send and receive Messages to Server`

```csharp
public static List<IClientSocket> Connections { get; }
```

`Read only ServerSocket instance, it used to send and receive Messages to connected clients`

```csharp
public static IServerSocket Server { get; }
```

`Read only Dictionary of SerializeFunctions, it is used to serialize out going data (payloads of Messages)`

```csharp
public static Dictionary<ushort, SerializeFunction> SerializeFuncs { get; }
```

`Read only Dictionary of DeserializeFunctions, it is used to Deserialize in coming data (payloads of Messages)`

```csharp
public static Dictionary<ushort, DeserializeFunction> DeserializeFuncs { get; }
```

## Events

`It is triggered on Settings (ServerConfig.xml) loaded`

```csharp
public static Action OnSettingsLoaded;
```

`It is triggered after creation of IServerSocket & IClientSockets`

```csharp
public static Action OnInitilized;
```

## Methods

`Load Configuration based on ServerConfig.xml`

```csharp
public static void LoadConfig();
```

`Create Instances of IServerSocket, IClientSockets and Modules based on Configuration`

```csharp
public static void Initilize();
public static void Initilize(Configuration config);
```

`Stop IServerSocket Instance & IClientSockets and dispose them`

```csharp
public static void Deinitialize();
```

`Load Modules as Plugin defined in ServerConfig.xml`

```csharp
public static void LoadModules(IServer server);
```

`Create ClientSocket Instance and Add it to FN.Connections list based on Peers in ServerConfig.xml`\
`Params` \
`int config : points to peers index in settings`\
`IClientSocketListner socketListner : pass an instance to receiver socket events`&#x20;

```csharp
public static void AddConnectionAndConnect(int config = 0, IClientSocketListener socketListener = null);
```

`Create ClientSocket Instance and Add it to FN.Connections list based on Peers in ServerConfig.xml`\
`Params` \
`PeerConfig peerConfig : PeerConfig that is used to create socket instance`\
`IClientSocketListner socketListner : pass an instance to receiver socket events`

```csharp
public static void AddConnectionAndConnect(PeerConfig peerConfig, IClientSocketListener socketListener = null);
```

`When AutoConnect is true in ServerConfig.xml, then this method can be used to bind listners to ClientSockets of FN.Connections.`\
`Note: call this method before OnInitialize event, OnSettingsLoaded event is a good place to register this event` &#x20;

```csharp
public static void BindClientListner(params IClientSocketListener[] listener);
```

`This method can be used to bind listner to ServerSockets of FN.Server`\
`Note: call this method before OnInitialize event, OnSettingsLoaded event is a good place to register this event` &#x20;

```csharp
public static void BindServerListner(IServerSocketListener listener);
```

`This method can be used to Remove a client connection from FN.Connections list and disconnect it by name`

```csharp
public static void RemoveConnectionAndDisconnect(string name);
```

`This method can be used to Remove a client connection from FN.Connections list and disconnect it by index of FN.Connections`

```csharp
public static void RemoveConnectionAndDisconnect(int config = 0);
```

This method is used to Register payload serialize and deserialize functions against messageId

```csharp
public static void RegisterPayload(ushort msgId, SerializeFunction serializeFunc, DeserializeFunction deserializeFunc);
```

`By default if Logging level is set to ALL in ServerConfig.xml, the logger will log detailed log of every comming messages. This method can be used to view detailed log of subscribed messages only.`&#x20;

```csharp
public static void SubscribeToDetailedLog(ushort messageId);
```

`This method is used to unsubscribe the detailed log of perticular message.`\
`Note: if there is no message is subscribed the logger will print all in comming message`

```csharp
public static void UnSubscribeToDetailedLog(ushort messageId);
```
