-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkMessages.cs
More file actions
83 lines (74 loc) · 2.69 KB
/
NetworkMessages.cs
File metadata and controls
83 lines (74 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Contains all the network messages that we need.
using System.Collections.Generic;
using System.Linq;
using Mirror;
namespace uMMORPG
{
// client to server ////////////////////////////////////////////////////////////
public partial struct LoginMsg : NetworkMessage
{
public string account;
public string password;
public string version;
}
public partial struct CharacterCreateMsg : NetworkMessage
{
public string name;
public int classIndex;
public PlayerCustomizationData customization;
public bool gameMaster; // only allowed if host connection!
}
public partial struct CharacterSelectMsg : NetworkMessage
{
public int index;
}
public partial struct CharacterDeleteMsg : NetworkMessage
{
public int index;
}
// server to client ////////////////////////////////////////////////////////////
// we need an error msg packet because we can't use TargetRpc with the Network-
// Manager, since it's not a MonoBehaviour.
public partial struct ErrorMsg : NetworkMessage
{
public string text;
public bool causesDisconnect;
}
public partial struct LoginSuccessMsg : NetworkMessage
{
}
public partial struct CharactersAvailableMsg : NetworkMessage
{
public partial struct CharacterPreview
{
public string name;
public string className; // = the prefab name
public bool isGameMaster; // for nameoverlay prefix in preview!
public PlayerCustomizationData customization;
public ItemSlot[] equipment;
}
public CharacterPreview[] characters;
// load method in this class so we can still modify the characters structs
// in the addon hooks
public void Load(List<Player> players)
{
// we only need name, class, equipment for our UI
// (avoid Linq because it is HEAVY(!) on GC and performance)
characters = new CharacterPreview[players.Count];
for (int i = 0; i < players.Count; ++i)
{
Player player = players[i];
characters[i] = new CharacterPreview
{
name = player.name,
className = player.className,
isGameMaster = player.isGameMaster,
equipment = player.equipment.slots.ToArray(),
customization = player.customization
};
}
// addon system hooks (to initialize extra values like health if necessary)
Utils.InvokeMany(typeof(CharactersAvailableMsg), this, "Load_", players);
}
}
}