forked from JiepengTan/Lockstep-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorCode.cs
More file actions
executable file
·78 lines (65 loc) · 2.43 KB
/
Copy pathErrorCode.cs
File metadata and controls
executable file
·78 lines (65 loc) · 2.43 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
using System;
namespace Lockstep.Network {
public class RpcException : Exception {
public int Error { get; private set; }
public RpcException(int error, string message) : base($"Error: {error} Message: {message}"){
this.Error = error;
}
public RpcException(int error, string message, Exception e) : base($"Error: {error} Message: {message}", e){
this.Error = error;
}
}
public static class ErrorCode {
public const int ERR_Success = 0;
public const int ERR_NotFoundActor = 2;
public const int ERR_AccountOrPasswordError = 102;
public const int ERR_SessionActorError = 103;
public const int ERR_NotFoundUnit = 104;
public const int ERR_ConnectGateKeyError = 105;
public const int ERR_Exception = 1000;
public const int ERR_RpcFail = 2001;
public const int ERR_SocketDisconnected = 2002;
public const int ERR_ReloadFail = 2003;
public const int ERR_ActorLocationNotFound = 2004;
}
public static class BytesHelper {
public static byte[] GetBytes(ushort val){
if (BitConverter.IsLittleEndian) {
return BitConverter.GetBytes(val);
}
else {
return BitConverter.GetBytes(val).Swap();
}
}
public static byte[] GetBytes(int val){
if (BitConverter.IsLittleEndian) {
return BitConverter.GetBytes(val);
}
else {
return BitConverter.GetBytes(val).Swap();
}
}
public static ushort ToUInt16(byte[] value, int startIndex){
if (BitConverter.IsLittleEndian) {
return BitConverter.ToUInt16(value, startIndex);
}
else {
return BitConverter.ToUInt16(value.Swap(startIndex, sizeof(ushort)), startIndex);
}
}
private static byte[] Swap(this byte[] vals, int startIdx, int len){
var dst = new byte[len];
Buffer.BlockCopy(vals, startIdx, dst, 0, len);
return Swap(dst);
}
private static byte[] Swap(this byte[] vals){
var count = vals.Length;
for (int i = 0, j = count - 1; i < j; ++i, --j) {
var temp = vals[i];
vals[i] = vals[j];
vals[j] = temp;
}
return vals;
}
}
}