@@ -33,26 +33,60 @@ namespace Mooege.Core.MooNet.Accounts
33
33
{
34
34
public class Account : PersistentRPCObject
35
35
{
36
- public D3 . PartyMessage . ScreenStatus ScreenStatus { get ; set ; }
36
+ // public D3.PartyMessage.ScreenStatus ScreenStatus { get; set; }
37
37
38
- //public MooNetClient LoggedInClient { get; set; }
39
- public bool IsOnline
40
- {
41
- get
38
+
39
+ public ByteStringPresenceField < D3 . OnlineService . EntityId > SelectedGameAccountField
40
+ = new ByteStringPresenceField < D3 . OnlineService . EntityId > ( FieldKeyHelper . Program . D3 , FieldKeyHelper . OriginatingClass . Account , 2 , 0 ) ;
41
+
42
+ public StringPresenceField RealIDTagField
43
+ = new StringPresenceField ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 1 , 0 ) ;
44
+
45
+ public ByteStringPresenceField < D3 . OnlineService . EntityId > LastSelectedHeroField
46
+ = new ByteStringPresenceField < D3 . OnlineService . EntityId > ( FieldKeyHelper . Program . D3 , FieldKeyHelper . OriginatingClass . Account , 1 , 0 ) ;
47
+
48
+ public BoolPresenceField AccountOnlineField
49
+ = new BoolPresenceField ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 2 , 0 ) ;
50
+
51
+ public StringPresenceField AccountBattleTagField
52
+ = new StringPresenceField ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 5 , 0 ) ;
53
+
54
+ public EntityIdPresenceFieldList GameAccountListField
55
+ = new EntityIdPresenceFieldList ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 4 , 0 ) ;
56
+
57
+ public bool IsOnline
58
+ {
59
+ get
42
60
{
43
61
//check if anygameAccounts are online
44
62
foreach ( var gameAccount in GameAccounts )
45
63
{
46
64
if ( gameAccount . Value . IsOnline ) return true ;
47
65
}
48
66
return false ;
49
- }
67
+ }
50
68
}
51
69
52
70
public string Email { get ; private set ; } // I - Username
53
71
public byte [ ] Salt { get ; private set ; } // s- User's salt.
54
72
public byte [ ] PasswordVerifier { get ; private set ; } // v - password verifier.
55
- public string Name { get ; private set ; }
73
+
74
+ //TODO: Eliminate this variable as it is used inside the Field property
75
+ private string _name ;
76
+ public string Name
77
+ {
78
+ get
79
+ {
80
+ return this . _name ;
81
+ }
82
+ private set
83
+ {
84
+ this . _name = value ;
85
+ this . RealIDTagField . Value = this . Name ;
86
+ this . AccountBattleTagField . Value = Name + "#" + HashCode . ToString ( "D4" ) ;
87
+ }
88
+ }
89
+
56
90
public int HashCode { get ; private set ; }
57
91
public string BattleTag
58
92
{
@@ -68,6 +102,7 @@ public string BattleTag
68
102
var split = value . Split ( '#' ) ;
69
103
this . Name = split [ 0 ] ;
70
104
this . HashCode = Convert . ToInt32 ( split [ 1 ] ) ;
105
+ this . AccountBattleTagField . Value = Name + "#" + HashCode . ToString ( "D4" ) ;
71
106
}
72
107
}
73
108
@@ -78,21 +113,44 @@ public Dictionary<ulong, GameAccount> GameAccounts
78
113
get { return GameAccountManager . GetGameAccountsForAccount ( this ) ; }
79
114
}
80
115
81
- public GameAccount CurrentGameAccount { get ; set ; }
116
+ //TODO: Eliminate completly this variable as it is stored already in the persistence field;
117
+ private GameAccount _currentGameAccount ;
118
+ public GameAccount CurrentGameAccount
119
+ {
120
+ get
121
+ {
122
+ return this . _currentGameAccount ;
123
+ }
124
+ set
125
+ {
126
+ this . LastSelectedGameAccount = value . D3GameAccountId ;
127
+ this . SelectedGameAccountField . Value = value . D3GameAccountId ;
128
+ this . _currentGameAccount = value ;
129
+ }
130
+ }
82
131
83
132
public static readonly D3 . OnlineService . EntityId AccountHasNoToons =
84
133
D3 . OnlineService . EntityId . CreateBuilder ( ) . SetIdHigh ( 0 ) . SetIdLow ( 0 ) . Build ( ) ;
85
134
135
+ //TODO: Eliminate this variable as it is stored already in the persistence field;
86
136
private D3 . OnlineService . EntityId _lastSelectedHero = AccountHasNoToons ;
87
137
public D3 . OnlineService . EntityId LastSelectedHero
88
138
{
89
139
get
90
140
{
141
+ if ( _lastSelectedHero == AccountHasNoToons )
142
+ {
143
+ var gameAccount = GameAccountManager . GetAccountByPersistentID ( this . LastSelectedGameAccount . IdLow ) ;
144
+ if ( gameAccount . Toons . Count > 0 )
145
+ _lastSelectedHero = gameAccount . Toons . First ( ) . Value . D3EntityID ;
146
+ this . LastSelectedHeroField . Value = _lastSelectedHero ;
147
+ }
91
148
return _lastSelectedHero ;
92
149
}
93
150
set
94
151
{
95
152
_lastSelectedHero = value ;
153
+ this . LastSelectedHeroField . Value = value ;
96
154
}
97
155
}
98
156
@@ -101,11 +159,15 @@ public D3.OnlineService.EntityId LastSelectedGameAccount
101
159
{
102
160
get
103
161
{
162
+ if ( _lastSelectedGameAccount == AccountHasNoToons && this . GameAccounts . Count > 0 )
163
+ _lastSelectedGameAccount = this . SelectedGameAccountField . Value = this . GameAccounts . First ( ) . Value . D3GameAccountId ;
104
164
return _lastSelectedGameAccount ;
105
165
}
106
166
set
107
167
{
108
168
_lastSelectedGameAccount = value ;
169
+ this . SelectedGameAccountField . Value = value ;
170
+
109
171
}
110
172
}
111
173
@@ -146,6 +208,7 @@ private void SetFields(string email, byte[] salt, byte[] passwordVerifier, strin
146
208
147
209
this . Name = battleTagName ;
148
210
this . HashCode = hashCode ;
211
+ this . AccountBattleTagField . Value = Name + "#" + HashCode . ToString ( "D4" ) ;
149
212
}
150
213
151
214
public bnet . protocol . presence . Field QueryField ( bnet . protocol . presence . FieldKey queryKey )
@@ -176,6 +239,13 @@ public bnet.protocol.presence.Field QueryField(bnet.protocol.presence.FieldKey q
176
239
177
240
#region Notifications
178
241
242
+ public override void NotifyUpdate ( )
243
+ {
244
+ var operations = ChangedFields . GetChangedFieldList ( ) ;
245
+ ChangedFields . ClearChanged ( ) ;
246
+ base . MakeRPC ( this . CurrentGameAccount . LoggedInClient , operations ) ;
247
+ }
248
+
179
249
//account class generated
180
250
//D3, Account,1,0 -> D3.OnlineService.EntityId: Last Played Hero
181
251
//D3, Account,2,0 -> LastSelectedGameAccount
@@ -186,90 +256,32 @@ public bnet.protocol.presence.Field QueryField(bnet.protocol.presence.FieldKey q
186
256
187
257
public override List < bnet . protocol . presence . FieldOperation > GetSubscriptionNotifications ( )
188
258
{
259
+ //TODO: Create delegate inside Persistence field so IsOnline can be removed
260
+ this . AccountOnlineField . Value = this . IsOnline ;
261
+ //TODO: Create delegate-move this out
262
+ this . GameAccountListField . Value . Clear ( ) ;
263
+ foreach ( var pair in this . GameAccounts . Values )
264
+ {
265
+ this . GameAccountListField . Value . Add ( pair . BnetEntityId ) ;
266
+ }
267
+
268
+
189
269
var operationList = new List < bnet . protocol . presence . FieldOperation > ( ) ;
190
270
191
271
if ( this . LastSelectedHero != AccountHasNoToons )
192
- operationList . Add ( GetCurrentlySelectedHeroNotification ( ) ) ;
272
+ operationList . Add ( this . LastSelectedHeroField . GetFieldOperation ( ) ) ;
193
273
if ( this . LastSelectedGameAccount != AccountHasNoToons )
194
- operationList . Add ( GetSelectedGameAccount ( ) ) ;
195
- operationList . Add ( GetAccountIsOnlineNotification ( ) ) ;
196
- operationList . AddRange ( GetGameAccountListNotification ( ) ) ;
197
- operationList . Add ( GetAccountBattleTagNotification ( ) ) ;
274
+ operationList . Add ( this . SelectedGameAccountField . GetFieldOperation ( ) ) ;
275
+ operationList . Add ( this . RealIDTagField . GetFieldOperation ( ) ) ;
276
+ operationList . Add ( this . AccountOnlineField . GetFieldOperation ( ) ) ;
277
+ operationList . AddRange ( this . GameAccountListField . GetFieldOperationList ( ) ) ;
278
+ operationList . Add ( this . AccountBattleTagField . GetFieldOperation ( ) ) ;
198
279
199
280
return operationList ;
200
281
}
201
282
202
- /// <summary>
203
- /// D3, Account, 2, 0: Selected Game Account
204
- /// </summary>
205
- /// <returns></returns>
206
- public bnet . protocol . presence . FieldOperation GetSelectedGameAccount ( )
207
- {
208
- var GameAccountKey = FieldKeyHelper . Create ( FieldKeyHelper . Program . D3 , FieldKeyHelper . OriginatingClass . Account , 2 , 0 ) ;
209
- var GameAccountField = bnet . protocol . presence . Field . CreateBuilder ( ) . SetKey ( GameAccountKey ) . SetValue ( bnet . protocol . attribute . Variant . CreateBuilder ( ) . SetMessageValue ( this . CurrentGameAccount . D3GameAccountId . ToByteString ( ) ) . Build ( ) ) . Build ( ) ;
210
- return bnet . protocol . presence . FieldOperation . CreateBuilder ( ) . SetField ( GameAccountField ) . Build ( ) ;
211
- }
212
-
213
- /// <summary>
214
- /// BNet, Account, 1, 0: RealIDTag
215
- /// </summary>
216
- /// <returns></returns>
217
- public bnet . protocol . presence . FieldOperation GetRealIDName ( )
218
- {
219
- var realNameKey = FieldKeyHelper . Create ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 1 , 0 ) ;
220
- var realNameField = bnet . protocol . presence . Field . CreateBuilder ( ) . SetKey ( realNameKey ) . SetValue ( bnet . protocol . attribute . Variant . CreateBuilder ( ) . SetStringValue ( this . Name ) . Build ( ) ) . Build ( ) ;
221
- return ( bnet . protocol . presence . FieldOperation . CreateBuilder ( ) . SetField ( realNameField ) . Build ( ) ) ;
222
- }
223
283
224
- /// <summary>
225
- /// D3, Account, 1, 0: Currently Selected Hero
226
- /// </summary>
227
- /// <returns></returns>
228
- public bnet . protocol . presence . FieldOperation GetCurrentlySelectedHeroNotification ( )
229
- {
230
- var ToonKey = FieldKeyHelper . Create ( FieldKeyHelper . Program . D3 , FieldKeyHelper . OriginatingClass . Account , 1 , 0 ) ;
231
- var ToonField = bnet . protocol . presence . Field . CreateBuilder ( ) . SetKey ( ToonKey ) . SetValue ( bnet . protocol . attribute . Variant . CreateBuilder ( ) . SetMessageValue ( this . LastSelectedHero . ToByteString ( ) ) . Build ( ) ) . Build ( ) ;
232
- return bnet . protocol . presence . FieldOperation . CreateBuilder ( ) . SetField ( ToonField ) . Build ( ) ;
233
- }
234
284
235
- /// <summary>
236
- /// BNet, Account, 2, 0: Account Online
237
- /// </summary>
238
- /// <returns></returns>
239
- public bnet . protocol . presence . FieldOperation GetAccountIsOnlineNotification ( )
240
- {
241
- var accountOnlineKey = FieldKeyHelper . Create ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 2 , 0 ) ;
242
- var accountOnlineField = bnet . protocol . presence . Field . CreateBuilder ( ) . SetKey ( accountOnlineKey ) . SetValue ( bnet . protocol . attribute . Variant . CreateBuilder ( ) . SetBoolValue ( this . IsOnline ) . Build ( ) ) . Build ( ) ;
243
- return bnet . protocol . presence . FieldOperation . CreateBuilder ( ) . SetField ( accountOnlineField ) . Build ( ) ;
244
- }
245
-
246
- /// <summary>
247
- /// BNet, Account, 5, 0: Account BattleTag
248
- /// </summary>
249
- /// <returns></returns>
250
- public bnet . protocol . presence . FieldOperation GetAccountBattleTagNotification ( )
251
- {
252
- var tempNameKey = FieldKeyHelper . Create ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 5 , 0 ) ;
253
- var tempNameField = bnet . protocol . presence . Field . CreateBuilder ( ) . SetKey ( tempNameKey ) . SetValue ( bnet . protocol . attribute . Variant . CreateBuilder ( ) . SetStringValue ( this . BattleTag ) . Build ( ) ) . Build ( ) ;
254
- return bnet . protocol . presence . FieldOperation . CreateBuilder ( ) . SetField ( tempNameField ) . Build ( ) ;
255
- }
256
-
257
- /// <summary>
258
- /// BNet, Account, 4, index: Account GameAccountList
259
- /// </summary>
260
- /// <returns></returns>
261
- public List < bnet . protocol . presence . FieldOperation > GetGameAccountListNotification ( )
262
- {
263
- var operationList = new List < bnet . protocol . presence . FieldOperation > ( ) ;
264
-
265
- foreach ( var pair in this . GameAccounts . Values )
266
- {
267
- var gameAccountKey = FieldKeyHelper . Create ( FieldKeyHelper . Program . BNet , FieldKeyHelper . OriginatingClass . Account , 4 , pair . BnetEntityId . High ) ;
268
- var gameAccountField = bnet . protocol . presence . Field . CreateBuilder ( ) . SetKey ( gameAccountKey ) . SetValue ( bnet . protocol . attribute . Variant . CreateBuilder ( ) . SetEntityidValue ( pair . BnetEntityId ) . Build ( ) ) . Build ( ) ;
269
- operationList . Add ( bnet . protocol . presence . FieldOperation . CreateBuilder ( ) . SetField ( gameAccountField ) . Build ( ) ) ;
270
- }
271
- return operationList ;
272
- }
273
285
#endregion
274
286
275
287
public bool VerifyPassword ( string password )
0 commit comments