Skip to content

Commit c0f38cd

Browse files
committed
[2] Fix for issue 2 - clientPool throw null exception
1 parent ba964b8 commit c0f38cd

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

COAN/Form1.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Windows.Forms;
43
using NLog;
54

@@ -11,7 +10,6 @@ public partial class Form1 : Form
1110

1211
private Config _config;
1312
readonly NetworkClient networkClient = new NetworkClient();
14-
public Dictionary<long, Client> clientPool = new Dictionary<long, Client>();
1513

1614
private void button1_Click(object sender, EventArgs e)
1715
{
@@ -46,7 +44,7 @@ void networkClient_OnChat(NetworkAction action, DestType dest, long clientId, st
4644
textBox2.Invoke(
4745
(MethodInvoker)delegate
4846
{
49-
textBox2.AppendText(Convert.ToString(clientPool[clientId].name));
47+
textBox2.AppendText(Convert.ToString(networkClient.GetClient(clientId).name));
5048
textBox2.AppendText(" said: " + message);
5149
textBox2.AppendText(Environment.NewLine);
5250
});

COAN/Network/NetworkClient.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Net.Sockets;
55
using System.Windows.Forms;
66
using NLog;
7+
using System.Collections.Generic;
78

89
namespace COAN
910
{
@@ -15,11 +16,18 @@ public class NetworkClient
1516
private Socket socket;
1617
private readonly Thread mThread;
1718

19+
public Dictionary<long, Client> clientPool = new Dictionary<long, Client>();
20+
1821
public string botName = Info.Title;
1922
public string botVersion = Info.Version;
2023

2124
public string adminPassword = "";
2225

26+
public Client GetClient(long id)
27+
{
28+
return clientPool[id];
29+
}
30+
2331
#region Delegates
2432
/// <summary>
2533
/// Fired when messages are recieved
@@ -279,7 +287,7 @@ public void receiveServerClientInfo(Packet p)
279287
client.joindate = new GameDate(p.readUint32());
280288
client.companyId = p.readUint8();
281289

282-
//openttd.clientPool.Add(client.clientId, client); THIS SHOULD BE IMPLEMENTED IN THE EVENT
290+
clientPool.Add(client.clientId, client);
283291

284292
OnClientInfo?.Invoke(client);
285293
}

0 commit comments

Comments
 (0)