Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 049461c

Browse files
authored
Merge pull request #3 from blockba5her/v1.1
V1.1 to master
2 parents d77e917 + 167dccd commit 049461c

10 files changed

Lines changed: 311 additions & 172 deletions

File tree

src/Client/Windows/DispatchMain.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,18 @@ public async void OnViewCivClick(object sender, EventArgs e)
5454

5555
if (result.Item2 != null)
5656
{
57-
Invoke((MethodInvoker)delegate
57+
if (!(string.IsNullOrEmpty(result.Item2?.First) || string.IsNullOrEmpty(result.Item2?.Last))) // Checking if the civilian is empty bc for some reason == and .Equals are not working for this situation
5858
{
59-
new CivView(result.Item2).Show();
60-
});
59+
Invoke((MethodInvoker)delegate
60+
{
61+
new CivView(result.Item2).Show();
62+
});
63+
}
64+
else
65+
MessageBox.Show("That name doesn't exist in the system!", "DispatchSystem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
6166
}
6267
else
63-
MessageBox.Show("That name doesn't exist in the system!", "DispatchSystem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
68+
MessageBox.Show("Invalid request", "DispatchSystem", MessageBoxButtons.OK, MessageBoxIcon.Error);
6469

6570
firstName.ResetText();
6671
lastName.ResetText();
@@ -83,13 +88,18 @@ private async void OnViewCivVehClick(object sender, EventArgs e)
8388

8489
if (result.Item2 != null)
8590
{
86-
Invoke((MethodInvoker)delegate
91+
if (!(string.IsNullOrEmpty(result.Item2.Plate)))
8792
{
88-
new CivVehView(result.Item2).Show();
89-
});
93+
Invoke((MethodInvoker)delegate
94+
{
95+
new CivVehView(result.Item2).Show();
96+
});
97+
}
98+
else
99+
MessageBox.Show("That plate doesn't exist in the system!", "DispatchSystem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
90100
}
91101
else
92-
MessageBox.Show("That plate doesn't exist in the system!", "DispatchSystem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
102+
MessageBox.Show("Invalid Request", "DispatchSystem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
93103

94104
plate.ResetText();
95105
}

src/Common/DataHolders/Storage/Civilian.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public string First
1414
{
1515
get
1616
{
17+
if (string.IsNullOrWhiteSpace(_first))
18+
return string.Empty;
1719
char[] str = _first.ToCharArray();
1820
for (int i = 0; i < str.Length; i++)
1921
{
@@ -31,6 +33,8 @@ public string Last
3133
{
3234
get
3335
{
36+
if (string.IsNullOrWhiteSpace(_last))
37+
return string.Empty;
3438
char[] str = _last.ToCharArray();
3539
for (int i = 0; i < str.Length; i++)
3640
{
@@ -139,5 +143,11 @@ public override object[] ToObjectArray()
139143
{
140144
return new[] { (object)First, (object)Last, (object)WarrantStatus, (object)CitationCount, (object)Notes, (object)Tickets };
141145
}
146+
147+
// Below is for communcation reasons between server and client
148+
// [NonSerialized]
149+
public static readonly Civilian Empty = new Civilian(null);
150+
// [NonSerialized]
151+
public static readonly Civilian Null = null;
142152
}
143153
}

src/Common/DataHolders/Storage/CivilianVeh.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CivilianVeh : CivilianBase, IDataHolder, IOwnable
1111
{
1212
public Civilian Owner { get; set; }
1313
protected string _plate;
14-
public string Plate { get => _plate.ToUpper(); set => _plate = value; }
14+
public string Plate { get => string.IsNullOrEmpty(_plate) ? string.Empty : _plate.ToUpper(); set => _plate = value; }
1515
public bool StolenStatus { get; set; }
1616
public bool Registered { get; set; }
1717
public bool Insured { get; set; }
@@ -43,5 +43,11 @@ public override object[] ToObjectArray()
4343
{
4444
return new[] { (object)Owner, (object)Plate, (object)StolenStatus, (object)Registered, (object)Insured };
4545
}
46+
47+
// Below is for communcation reasons between server and client
48+
[NonSerialized]
49+
public static readonly CivilianVeh Empty = new CivilianVeh(null);
50+
[NonSerialized]
51+
public static readonly CivilianVeh Null = null;
4652
}
4753
}

src/Server/Command.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
using CitizenFX.Core;
8+
9+
namespace DispatchSystem.sv
10+
{
11+
public delegate Task<bool> CommandCallback(Player invoker, string[] args);
12+
public enum CommandType
13+
{
14+
Leo,
15+
Civilian
16+
}
17+
public class Command
18+
{
19+
private CommandCallback _callback = null;
20+
public CommandCallback Callback { get => _callback; set => _callback = value; }
21+
22+
private CommandType _type;
23+
public CommandType Type { get => _type; set => _type = value; }
24+
25+
public Command(CommandType type) => _type = type;
26+
}
27+
}

src/Server/DispatchSystem/Events.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public static void DipslayCivilianNotes(string handle, string first, string last
282282
}
283283
#endregion
284284

285-
private void OnChatMessage(int source, string n, string msg)
285+
private async void OnChatMessage(int source, string n, string msg)
286286
{
287287
Player p = this.Players[source];
288288
var args = msg.Split(' ').ToList();
@@ -292,31 +292,31 @@ private void OnChatMessage(int source, string n, string msg)
292292
if (commands.ContainsKey(cmd))
293293
{
294294
CancelEvent();
295-
if (commands[cmd].Item2 == CommandType.Civilian)
295+
if (commands[cmd].Type == CommandType.Civilian)
296296
{
297297
if (perms.CivilianPermission == Permission.Specific)
298298
{
299299
if (perms.CivContains(IPAddress.Parse(p.Identifiers["ip"])))
300-
commands[cmd].Item1.Invoke(p, args.ToArray());
300+
await commands[cmd].Callback(p, args.ToArray());
301301
else
302302
SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You don't have the permission to do that!");
303303
}
304304
else if (perms.CivilianPermission == Permission.Everyone)
305-
commands[cmd].Item1.Invoke(p, args.ToArray());
305+
await commands[cmd].Callback(p, args.ToArray());
306306
else
307307
SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You don't have the permission to do that!");
308308
}
309-
else if (commands[cmd].Item2 == CommandType.Leo)
309+
else if (commands[cmd].Type == CommandType.Leo)
310310
{
311311
if (perms.LeoPermission == Permission.Specific)
312312
{
313313
if (perms.LeoContains(IPAddress.Parse(p.Identifiers["ip"])))
314-
commands[cmd].Item1.Invoke(p, args.ToArray());
314+
await commands[cmd].Callback(p, args.ToArray());
315315
else
316316
SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You don't have the permission to do that!");
317317
}
318318
else if (perms.LeoPermission == Permission.Everyone)
319-
commands[cmd].Item1.Invoke(p, args.ToArray());
319+
await commands[cmd].Callback(p, args.ToArray());
320320
else
321321
SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You don't have the permission to do that!");
322322
}

0 commit comments

Comments
 (0)