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

Last change on this file since 197 was 161, checked in by alloc, 10 years ago

fixes

File size: 2.5 KB
RevLine 
[144]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;
[146]15 [OptionalField]
16 private DateTime
17 lastOnline;
[144]18 private Inventory inventory;
[154]19 [OptionalField]
20 private int
21 lastPositionX, lastPositionY, lastPositionZ;
[144]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 {
[161]35 get { return name == null ? string.Empty : name; }
[144]36 }
37
38 public string IP {
[161]39 get { return ip == null ? string.Empty : ip; }
[144]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
[146]78 public DateTime LastOnline {
79 get {
80 if (IsOnline)
81 return DateTime.Now;
82 else
83 return lastOnline;
84 }
85 }
86
[154]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
[144]96 public void SetOffline ()
97 {
[161]98 if (clientInfo != null) {
99 Log.Out ("Player set to offline: " + steamId);
100 Vector3i lastPos = new Vector3i (Entity.GetPosition ());
101 lastPositionX = lastPos.x;
102 lastPositionY = lastPos.y;
103 lastPositionZ = lastPos.z;
104 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
105 lastOnline = DateTime.Now;
106 clientInfo = null;
107 }
[144]108 }
109
110 public void SetOnline (ClientInfo ci)
111 {
112 Log.Out ("Player set to online: " + steamId);
113 clientInfo = ci;
114 entityId = CommonMappingFunctions.GetEntityID (ci);
115 name = CommonMappingFunctions.GetPlayerName (ci);
116 ip = ci.networkPlayer.ipAddress;
117 }
118
119 public Player (string steamId)
120 {
121 this.steamId = steamId;
122 this.inventory = new Inventory ();
123 }
124
125
126 }
127}
Note: See TracBrowser for help on using the repository browser.