Skip to content

Commit

Permalink
[2] Fix for issue 2 - clientPool throw null exception
Browse files Browse the repository at this point in the history
  • Loading branch information
matt40k committed Dec 22, 2020
1 parent ba964b8 commit c0f38cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 1 addition & 3 deletions COAN/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using NLog;

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

private Config _config;
readonly NetworkClient networkClient = new NetworkClient();
public Dictionary<long, Client> clientPool = new Dictionary<long, Client>();

private void button1_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -46,7 +44,7 @@ void networkClient_OnChat(NetworkAction action, DestType dest, long clientId, st
textBox2.Invoke(
(MethodInvoker)delegate
{
textBox2.AppendText(Convert.ToString(clientPool[clientId].name));
textBox2.AppendText(Convert.ToString(networkClient.GetClient(clientId).name));
textBox2.AppendText(" said: " + message);
textBox2.AppendText(Environment.NewLine);
});
Expand Down
10 changes: 9 additions & 1 deletion COAN/Network/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net.Sockets;
using System.Windows.Forms;
using NLog;
using System.Collections.Generic;

namespace COAN
{
Expand All @@ -15,11 +16,18 @@ public class NetworkClient
private Socket socket;
private readonly Thread mThread;

public Dictionary<long, Client> clientPool = new Dictionary<long, Client>();

public string botName = Info.Title;
public string botVersion = Info.Version;

public string adminPassword = "";

public Client GetClient(long id)
{
return clientPool[id];
}

#region Delegates
/// <summary>
/// Fired when messages are recieved
Expand Down Expand Up @@ -279,7 +287,7 @@ public void receiveServerClientInfo(Packet p)
client.joindate = new GameDate(p.readUint32());
client.companyId = p.readUint8();

//openttd.clientPool.Add(client.clientId, client); THIS SHOULD BE IMPLEMENTED IN THE EVENT
clientPool.Add(client.clientId, client);

OnClientInfo?.Invoke(client);
}
Expand Down

0 comments on commit c0f38cd

Please sign in to comment.