-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNetworking.txt
More file actions
74 lines (57 loc) · 2.57 KB
/
Networking.txt
File metadata and controls
74 lines (57 loc) · 2.57 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
net_threshold_multiplier = 2.0f;
Syncs the position forcefully if the change in position between old and new position is larger than threshold (presumably. it's complicated)
A higher threshold means the position gets synced less.
Try to avoid using CPlayer.set stuff, it often doesn't work. And what really doesn't work is using .Sync() on CPlayer, don't do that at all.
sending a command.
rules.addCommandID("sendvalues");//Should generally be put in onInit(CRules)
CBitStream params;//Create the parameters to be sent. Keep in mind, you aren't required to send anything.
params.write_u8(27);//Write the value 27 to be sent through the command.
params.write_string("hmm yes, string");//Write a string to be sent through the command.
rules.SendCommand(rules.getCommandID("sendvalues"), params);//Sends the command to everyone including self with the params. (see the manual for different variations of SendCommand to change who gets it.)
void onCommand(CRules@ rules, u8 cmd, CBitStream@ params)
{
if(cmd == rules.getCommandID("sendvalues"))//Our sendvalues command.
{
u8 sent_value;
if(!params.saferead_u8(sent_value)) { error("sendvalues failed to saferead u8"); return; }
string sent_string;
if(!params.saferead_string(sent_string)) { error("sendvalues failed to saferead string"); return; }
//Whatever got this command now has that u8 and string. Do whatever logic you want here.
}
else if(cmd == rules.getCommandID("anything"))//Other commands.
{
}
}
When you want to store the CBitStream from the onCommand hook for future use.
CBitStream bs;
bs = params;
bs.SetBitIndex(params.getBitIndex());
@stored_params = @bs;
(as of 2022, month 5)
CBlob.server_SendCommandToPlayer()//sends a command to the server too for some awful reason.
CBlob.SendCommandOnlyServer()//a client that sends this command, will also get this command.
CRules.SendCommand(uint8 cmd, CBitStream&in params, bool sendToClients)//When sendToClients is false, and this is used on a client, the client gets this command too.
if(isServer())
{
//Server and localhost get here
}
if(isClient())
{
//Client and localhost
}
if(!isClient())
{
//Only server gets here
}
if(!isServer())
{
//Only client gets here
}
if(isClient()) { return; }
//Only server past this point
if(!isServer()){ return; }
//Client and localhost past this point
if(isServer()) { return; }
//Only client past this point, no localhost
if(!isClient()) { return; }
//Server and localhost past this point