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

Last change on this file since 144 was 144, checked in by alloc, 11 years ago

Fixes

File size: 1.8 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 private Inventory inventory;
16 [NonSerialized]
17 private ClientInfo
18 clientInfo;
19
20 public string SteamID {
21 get { return steamId; }
22 }
23
24 public int EntityID {
25 get { return entityId; }
26 set { entityId = value; }
27 }
28
29 public string Name {
30 get { return name; }
31 set { name = value; }
32 }
33
34 public string IP {
35 get { return ip; }
36 set { ip = value; }
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 void SetOffline ()
76 {
77 Log.Out ("Player set to offline: " + steamId);
78 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
79 clientInfo = null;
80 }
81
82 public void SetOnline (ClientInfo ci)
83 {
84 Log.Out ("Player set to online: " + steamId);
85 clientInfo = ci;
86 entityId = CommonMappingFunctions.GetEntityID (ci);
87 name = CommonMappingFunctions.GetPlayerName (ci);
88 ip = ci.networkPlayer.ipAddress;
89 }
90
91 public Player (string steamId)
92 {
93 this.steamId = steamId;
94 this.inventory = new Inventory ();
95 }
96
97
98 }
99}
Note: See TracBrowser for help on using the repository browser.