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

Last change on this file since 152 was 146, checked in by alloc, 10 years ago

Fixes

File size: 2.0 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 [NonSerialized]
20 private ClientInfo
21 clientInfo;
22
23 public string SteamID {
24 get { return steamId; }
25 }
26
27 public int EntityID {
28 get { return entityId; }
29 }
30
31 public string Name {
32 get { return name; }
33 }
34
35 public string IP {
36 get { return ip; }
37 }
38
39 public Inventory Inventory {
40 get {
41 if (inventory == null)
42 inventory = new Inventory ();
43 return inventory;
44 }
45 }
46
47 public bool IsOnline {
48 get { return clientInfo != null; }
49 }
50
51 public ClientInfo ClientInfo {
52 get { return clientInfo; }
53 }
54
55 public EntityPlayer Entity {
56 get {
57 if (IsOnline) {
58 return CommonMappingFunctions.GetEntityPlayer (clientInfo);
59 } else {
60 return null;
61 }
62 }
63 }
64
65 public long TotalPlayTime {
66 get {
67 if (IsOnline) {
68 return totalPlayTime + (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
69 } else {
70 return totalPlayTime;
71 }
72 }
73 }
74
75 public DateTime LastOnline {
76 get {
77 if (IsOnline)
78 return DateTime.Now;
79 else
80 return lastOnline;
81 }
82 }
83
84 public void SetOffline ()
85 {
86 Log.Out ("Player set to offline: " + steamId);
87 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
88 lastOnline = DateTime.Now;
89 clientInfo = null;
90 }
91
92 public void SetOnline (ClientInfo ci)
93 {
94 Log.Out ("Player set to online: " + steamId);
95 clientInfo = ci;
96 entityId = CommonMappingFunctions.GetEntityID (ci);
97 name = CommonMappingFunctions.GetPlayerName (ci);
98 ip = ci.networkPlayer.ipAddress;
99 }
100
101 public Player (string steamId)
102 {
103 this.steamId = steamId;
104 this.inventory = new Inventory ();
105 }
106
107
108 }
109}
Note: See TracBrowser for help on using the repository browser.