@@ -23,12 +23,12 @@ func (k msgServer) GuildMembershipJoinProxy(goCtx context.Context, msg *types.Ms
2323 k .AddressEmitActivity (ctx , msg .Creator )
2424
2525 // Look up requesting account
26- proxyPlayer := k .UpsertPlayer (ctx , msg .Creator )
26+ proxyPlayer := cc .UpsertPlayer (msg .Creator )
2727
2828 // look up destination guild
29- guild , guildFound := k .GetGuild (ctx , proxyPlayer .GuildId )
30- if ! guildFound {
31- return & types.MsgGuildMembershipResponse {}, types .NewObjectNotFoundError ("guild" , proxyPlayer .GuildId )
29+ guild := cc .GetGuild (proxyPlayer .GetGuildId () )
30+ if guild . CheckGuild () != nil {
31+ return & types.MsgGuildMembershipResponse {}, types .NewObjectNotFoundError ("guild" , proxyPlayer .GetGuildId () )
3232 }
3333
3434 // Decode the PubKey from hex Encoding
@@ -54,10 +54,10 @@ func (k msgServer) GuildMembershipJoinProxy(goCtx context.Context, msg *types.Ms
5454 //
5555 // A playerIndex of 0 should never return anything other than a nonce of 0
5656 playerIndex := k .GetPlayerIndexFromAddress (ctx , msg .Address )
57- nonce := k .GetGridAttribute (ctx , GetGridAttributeID (types .GridAttributeType_proxyNonce , types .ObjectType_player , playerIndex ))
57+ nonce := cc .GetGridAttribute (GetGridAttributeID (types .GridAttributeType_proxyNonce , types .ObjectType_player , playerIndex ))
5858
5959 // We rebuild the message manually here rather than trust the client to provide it
60- hashInput := fmt .Sprintf ("GUILD%sADDRESS%sNONCE%d" , guild .Id , msg .Address , nonce )
60+ hashInput := fmt .Sprintf ("GUILD%sADDRESS%sNONCE%d" , guild .GetGuildId () , msg .Address , nonce )
6161
6262 /*
6363 fmt.Printf("Hash: %s \n", hashInput)
@@ -82,22 +82,21 @@ func (k msgServer) GuildMembershipJoinProxy(goCtx context.Context, msg *types.Ms
8282 return & types.MsgGuildMembershipResponse {}, types .NewAddressValidationError (msg .Address , "signature_invalid" )
8383 }
8484
85- guildObjectPermissionId := GetObjectPermissionIDBytes (guild .Id , proxyPlayer .Id )
85+ guildObjectPermissionId := GetObjectPermissionIDBytes (guild .GetGuildId () , proxyPlayer .GetPlayerId () )
8686 addressPermissionId := GetAddressPermissionIDBytes (msg .Creator )
8787
8888 // Check to make sure the player has permissions on the guild
89- if ! k .PermissionHasOneOf (ctx , guildObjectPermissionId , types .PermissionAssociations ) {
90- return & types.MsgGuildMembershipResponse {}, types .NewPermissionError ("player" , proxyPlayer .Id , "guild" , guild .Id , uint64 (types .PermissionAssociations ), "register_player" )
89+ if ! cc .PermissionHasOneOf (guildObjectPermissionId , types .PermissionAssociations ) {
90+ return & types.MsgGuildMembershipResponse {}, types .NewPermissionError ("player" , proxyPlayer .GetPlayerId () , "guild" , guild .GetGuildId () , uint64 (types .PermissionAssociations ), "register_player" )
9191 }
9292
9393 // Make sure the address calling this has Associate permissions
94- if ! k .PermissionHasOneOf (ctx , addressPermissionId , types .PermissionAssociations ) {
94+ if ! cc .PermissionHasOneOf (addressPermissionId , types .PermissionAssociations ) {
9595 return & types.MsgGuildMembershipResponse {}, types .NewPermissionError ("address" , msg .Creator , "" , "" , uint64 (types .PermissionAssociations ), "guild_management" )
9696 }
9797
98- var substation types.Substation
99- substationFound := false
100-
98+ var substation * SubstationCache
99+ substationSet := false
101100 /* Look up destination substation
102101 *
103102 * We're going to try and load up the substation override first
@@ -109,62 +108,59 @@ func (k msgServer) GuildMembershipJoinProxy(goCtx context.Context, msg *types.Ms
109108 */
110109
111110 if msg .SubstationId != "" {
112- substation , substationFound = k .GetSubstation (ctx , msg .SubstationId )
113- if ! substationFound {
111+ substation = cc .GetSubstation (msg .SubstationId )
112+ if substation . CheckSubstation () != nil {
114113 return & types.MsgGuildMembershipResponse {}, types .NewObjectNotFoundError ("substation" , msg .SubstationId ).WithContext ("override substation" )
115114 }
116115
117116 // Since the Guild Entry Substation is being overridden, let's make
118117 // sure the ProxyPlayer actually have authority over this substation
119- substationObjectPermissionId := GetObjectPermissionIDBytes (substation .Id , proxyPlayer .Id )
120- if ! k .PermissionHasOneOf (ctx , substationObjectPermissionId , types .PermissionGrid ) {
121- return & types.MsgGuildMembershipResponse {}, types .NewPermissionError ("player" , proxyPlayer .Id , "substation" , substation .Id , uint64 (types .PermissionGrid ), "player_connect" )
118+ substationObjectPermissionId := GetObjectPermissionIDBytes (substation .GetSubstationId () , proxyPlayer .GetPlayerId () )
119+ if ! cc .PermissionHasOneOf (substationObjectPermissionId , types .PermissionGrid ) {
120+ return & types.MsgGuildMembershipResponse {}, types .NewPermissionError ("player" , proxyPlayer .GetPlayerId () , "substation" , substation .GetSubstationId () , uint64 (types .PermissionGrid ), "player_connect" )
122121 }
122+ substationSet = true
123123 }
124124
125- if ! substationFound {
126- substation , substationFound = k .GetSubstation (ctx , guild .EntrySubstationId )
127- if ! substationFound {
128- return & types.MsgGuildMembershipResponse {}, types .NewObjectNotFoundError ("substation" , guild .EntrySubstationId ) .WithContext ("guild entry substation for " + guild .Id )
125+ if ! substationSet {
126+ substation = cc .GetSubstation (guild .GetEntrySubstationId () )
127+ if substation . CheckSubstation () != nil {
128+ return & types.MsgGuildMembershipResponse {}, types .NewObjectNotFoundError ("substation" , guild .GetEntrySubstationId ()) .WithContext ("guild entry substation for " + guild .GetGuildId () )
129129 }
130130 }
131131
132132 // create new player
133- player := k .UpsertPlayer (ctx , msg .Address )
133+ player := cc .UpsertPlayer (msg .Address )
134134
135- if player .GuildId != "" {
135+ if player .GetGuildId () != "" {
136136 // TODO new guild setting that dictates what to do when a player leaves
137137 // If already in a guild, leave permissions as-is?
138138 // Force disconnection of Substation?
139139
140140 // look up old guild
141- oldGuild , _ := k .GetGuild (ctx , player .GuildId )
141+ oldGuild := cc .GetGuild (player .GetGuildId () )
142142
143143 // Let's only disconnect the player if it's the main substation for the guild
144144 // Otherwise it might be there own substation and maybe they don't really want
145145 // that fucked with. Could also throw a flag in the calling message to force this.
146- if player .SubstationId != "" && player .SubstationId == oldGuild .EntrySubstationId {
147- player , _ = k . SubstationDisconnectPlayer ( ctx , player )
146+ if player .GetSubstationId () != "" && player .GetSubstationId () == oldGuild .GetEntrySubstationId () {
147+ player . DisconnectSubstation ( )
148148 }
149149 }
150150
151151 // Add player to the guild
152- player .GuildId = guild .Id
152+ player .SetGuild ( guild .GetGuildId ())
153153
154154 // Connect player to the substation
155155 // Now let's get the player some power
156- if player .SubstationId == "" {
156+ if player .GetSubstationId () == "" {
157157 // Connect Player to Substation
158- k .SubstationConnectPlayer (ctx , substation , player )
159- } else {
160- k .SetPlayer (ctx , player )
158+ player .MigrateSubstation (substation .GetSubstationId ())
161159 }
162160
163- _ = cc
164-
165161 // The proxy join has completely mostly successfully at this point
166162 // Increase the nonce of the player account to prevent replay of this signed message
167- k .SetGridAttributeIncrement (ctx , GetGridAttributeIDByObjectId (types .GridAttributeType_proxyNonce , player .Id ), 1 )
163+ cc .SetGridAttributeIncrement (GetGridAttributeIDByObjectId (types .GridAttributeType_proxyNonce , player .GetPlayerId () ), 1 )
168164
169165 return & types.MsgGuildMembershipResponse {}, nil
170166}
0 commit comments