source: binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs@ 160

Last change on this file since 160 was 154, checked in by alloc, 10 years ago

fixes

File size: 2.4 KB
Line 
1using System;
2using System.Runtime.Serialization;
3using UnityEngine;
4
5namespace AllocsFixes.PersistentData
6{
7 [Serializable]
8 public class Player
9 {
10 private readonly string steamId;
11 private int entityId;
12 private string name;
13 private string ip;
14 private long totalPlayTime;
15 [OptionalField]
16 private DateTime
17 lastOnline;
18 private Inventory inventory;
19 [OptionalField]
20 private int
21 lastPositionX, lastPositionY, lastPositionZ;
22 [NonSerialized]
23 private ClientInfo
24 clientInfo;
25
26 public string SteamID {
27 get { return steamId; }
28 }
29
30 public int EntityID {
31 get { return entityId; }
32 }
33
34 public string Name {
35 get { return name; }
36 }
37
38 public string IP {
39 get { return ip; }
40 }
41
42 public Inventory Inventory {
43 get {
44 if (inventory == null)
45 inventory = new Inventory ();
46 return inventory;
47 }
48 }
49
50 public bool IsOnline {
51 get { return clientInfo != null; }
52 }
53
54 public ClientInfo ClientInfo {
55 get { return clientInfo; }
56 }
57
58 public EntityPlayer Entity {
59 get {
60 if (IsOnline) {
61 return CommonMappingFunctions.GetEntityPlayer (clientInfo);
62 } else {
63 return null;
64 }
65 }
66 }
67
68 public long TotalPlayTime {
69 get {
70 if (IsOnline) {
71 return totalPlayTime + (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
72 } else {
73 return totalPlayTime;
74 }
75 }
76 }
77
78 public DateTime LastOnline {
79 get {
80 if (IsOnline)
81 return DateTime.Now;
82 else
83 return lastOnline;
84 }
85 }
86
87 public Vector3i LastPosition {
88 get {
89 if (IsOnline)
90 return new Vector3i (Entity.GetPosition ());
91 else
92 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ);
93 }
94 }
95
96 public void SetOffline ()
97 {
98 Log.Out ("Player set to offline: " + steamId);
99 Vector3i lastPos = new Vector3i (Entity.GetPosition ());
100 lastPositionX = lastPos.x;
101 lastPositionY = lastPos.y;
102 lastPositionZ = lastPos.z;
103 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
104 lastOnline = DateTime.Now;
105 clientInfo = null;
106 }
107
108 public void SetOnline (ClientInfo ci)
109 {
110 Log.Out ("Player set to online: " + steamId);
111 clientInfo = ci;
112 entityId = CommonMappingFunctions.GetEntityID (ci);
113 name = CommonMappingFunctions.GetPlayerName (ci);
114 ip = ci.networkPlayer.ipAddress;
115 }
116
117 public Player (string steamId)
118 {
119 this.steamId = steamId;
120 this.inventory = new Inventory ();
121 }
122
123
124 }
125}
Note: See TracBrowser for help on using the repository browser.