Skip to content

Commit 4b0eabe

Browse files
author
abstrct
committed
More permissions refactoring and fixing most struct action transactions
1 parent 3c15bbc commit 4b0eabe

28 files changed

+183
-361
lines changed

x/structs/keeper/current_context.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,6 @@ func (cc *CurrentContext) CommitAll() {
217217

218218

219219

220-
221-
222-
223-
224-
225-
226220
cc.committed = true
227221
/*
228222
TODO
@@ -231,38 +225,3 @@ func (cc *CurrentContext) CommitAll() {
231225
)
232226
*/
233227
}
234-
235-
// Reset clears all caches but keeps the context usable.
236-
// Useful for long-running operations (like ABCI hooks) that want to
237-
// commit periodically to avoid memory buildup.
238-
func (cc *CurrentContext) Reset() {
239-
// Commit any pending changes first
240-
if !cc.committed {
241-
cc.CommitAll()
242-
}
243-
244-
// Re-initialize all maps
245-
cc.agreements = make(map[string]*AgreementCache)
246-
cc.fleets = make(map[uint64]*FleetCache)
247-
cc.guilds = make(map[string]*GuildCache)
248-
cc.guildMembershipApps = make(map[string]*GuildMembershipApplicationCache)
249-
cc.infusions = make(map[string]*InfusionCache)
250-
cc.planets = make(map[string]*PlanetCache)
251-
cc.players = make(map[string]*PlayerCache)
252-
cc.providers = make(map[string]*ProviderCache)
253-
cc.structs = make(map[string]*StructCache)
254-
cc.substations = make(map[string]*SubstationCache)
255-
256-
cc.gridAttributes = make(map[string]*GridAttributeCache)
257-
cc.structAttributes = make(map[string]*StructAttributeCache)
258-
cc.planetAttributes = make(map[string]*PlanetAttributeCache)
259-
260-
cc.addresses = make(map[string]*AddressCache)
261-
cc.allocations = make(map[string]*AllocationCache)
262-
cc.permissions = make(map[string]*PermissionsCache)
263-
cc.reactors = make(map[string]*ReactorCache)
264-
cc.structTypes = make(map[uint64]*StructTypeCache)
265-
266-
267-
cc.committed = false
268-
}

x/structs/keeper/msg_server_permission_set_on_address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (k msgServer) PermissionSetOnAddress(goCtx context.Context, msg *types.MsgP
4040
}
4141

4242
targetAddressPermissionId := GetAddressPermissionIDBytes(msg.Address)
43-
cc.SetPermissions(targetAddressPermissionId, msg.Permissions)
43+
cc.SetPermissions(targetAddressPermissionId, types.Permission(msg.Permissions))
4444

4545
return &types.MsgPermissionResponse{}, nil
4646
}

x/structs/keeper/msg_server_permission_set_on_object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (k msgServer) PermissionSetOnObject(goCtx context.Context, msg *types.MsgPe
4343
}
4444

4545
targetPlayerPermissionId := GetObjectPermissionIDBytes(msg.ObjectId, msg.PlayerId)
46-
cc.SetPermissions(targetPlayerPermissionId, msg.Permissions)
46+
cc.SetPermissions(targetPlayerPermissionId, types.Permission(msg.Permissions))
4747

4848
return &types.MsgPermissionResponse{}, nil
4949
}

x/structs/keeper/msg_server_struct_activate.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,18 @@ func (k msgServer) StructActivate(goCtx context.Context, msg *types.MsgStructAct
2626
return &types.MsgStructStatusResponse{}, permissionError
2727
}
2828

29-
if structure.GetOwner().IsHalted() {
30-
return &types.MsgStructStatusResponse{}, types.NewPlayerHaltedError(structure.GetOwnerId(), "struct_activate").WithStruct(msg.StructId)
31-
}
32-
3329
// Check Activation Readiness
3430
// Check Struct is Built
3531
// Check Struct is Offline
3632
// Check Player is Online
3733
// Check Player capacity
3834
readinessError := structure.ActivationReadinessCheck()
3935
if (readinessError != nil) {
40-
k.DischargePlayer(ctx, structure.GetOwnerId())
4136
return &types.MsgStructStatusResponse{}, readinessError
4237
}
4338

44-
playerCharge := k.GetPlayerCharge(ctx, structure.GetOwnerId())
45-
if (playerCharge < structure.GetStructType().GetActivateCharge()) {
46-
k.DischargePlayer(ctx, structure.GetOwnerId())
47-
return &types.MsgStructStatusResponse{}, types.NewInsufficientChargeError(structure.GetOwnerId(), structure.GetStructType().GetActivateCharge(), playerCharge, "activate").WithStructType(structure.GetTypeId()).WithStructId(msg.StructId)
39+
if structure.GetOwner().GetCharge() < structure.GetStructType().ActivateCharge {
40+
return &types.MsgStructStatusResponse{}, types.NewInsufficientChargeError(structure.GetOwnerId(), structure.GetStructType().ActivateCharge, structure.GetOwner().GetCharge(), "activate").WithStructType(structure.GetTypeId()).WithStructId(msg.StructId)
4841
}
4942

5043
structure.GoOnline()

x/structs/keeper/msg_server_struct_attack.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ func (k msgServer) StructAttack(goCtx context.Context, msg *types.MsgStructAttac
2626
return &types.MsgStructAttackResponse{}, permissionError
2727
}
2828

29-
if structure.GetOwner().IsHalted() {
30-
return &types.MsgStructAttackResponse{}, types.NewPlayerHaltedError(structure.GetOwnerId(), "struct_attack").WithStruct(msg.OperatingStructId)
31-
}
32-
3329
// Is the Struct & Owner online?
3430
readinessError := structure.ReadinessCheck()
3531
if readinessError != nil {
@@ -50,9 +46,8 @@ func (k msgServer) StructAttack(goCtx context.Context, msg *types.MsgStructAttac
5046
return &types.MsgStructAttackResponse{}, weaponSystemError
5147
}
5248

53-
playerCharge := k.GetPlayerCharge(ctx, structure.GetOwnerId())
54-
if playerCharge < structure.GetStructType().GetWeaponCharge(weaponSystem) {
55-
return &types.MsgStructAttackResponse{}, types.NewInsufficientChargeError(structure.GetOwnerId(), structure.GetStructType().GetWeaponCharge(weaponSystem), playerCharge, "attack").WithStructType(structure.GetTypeId())
49+
if structure.GetOwner().GetCharge() < structure.GetStructType().GetWeaponCharge(weaponSystem) {
50+
return &types.MsgStructAttackResponse{}, types.NewInsufficientChargeError(structure.GetOwnerId(), structure.GetStructType().GetWeaponCharge(weaponSystem), structure.GetOwner().GetCharge(), "attack").WithStructType(structure.GetTypeId())
5651
}
5752

5853
// Jump out of Stealth Mode for the attack
@@ -115,7 +110,6 @@ func (k msgServer) StructAttack(goCtx context.Context, msg *types.MsgStructAttac
115110
if (structure.GetStructType().GetWeaponBlockable(weaponSystem)) || (structure.GetStructType().GetWeaponCounterable(weaponSystem)) {
116111

117112
// Check the Defenders
118-
defenderPlayer := targetStructure.GetOwner()
119113
defenders := targetStructure.GetDefenders()
120114
for _, defender := range defenders {
121115
k.logger.Info("Defender at Location", "defender", defender.GetStructId(), "locationId", defender.GetLocationId())
@@ -124,7 +118,6 @@ func (k msgServer) StructAttack(goCtx context.Context, msg *types.MsgStructAttac
124118
defender = cc.GetStruct(defender.GetStructId())
125119

126120
defender.Defender = true
127-
defender.ManualLoadOwner(defenderPlayer)
128121
defender.ManualLoadEventAttackDetail(eventAttackDetail)
129122
defender.ManualLoadEventAttackShotDetail(eventAttackShotDetail)
130123

@@ -168,7 +161,7 @@ func (k msgServer) StructAttack(goCtx context.Context, msg *types.MsgStructAttac
168161

169162
structure.GetEventAttackDetail().AppendShot(targetStructure.FlushEventAttackShotDetail())
170163

171-
if targetStructure.GetStructType().GetCategory() == types.ObjectType_planet {
164+
if targetStructure.GetStructType().Category == types.ObjectType_planet {
172165
targetWasPlanetary = true
173166
targetWasOnPlanet = targetStructure.GetPlanet()
174167
}
@@ -187,7 +180,7 @@ func (k msgServer) StructAttack(goCtx context.Context, msg *types.MsgStructAttac
187180

188181
_ = ctx.EventManager().EmitTypedEvent(&types.EventAttack{EventAttackDetail: eventAttackDetail})
189182

190-
k.DischargePlayer(ctx, structure.GetOwnerId())
183+
structure.GetOwner().Discharge()
191184

192185
if ctx.ExecMode() == sdk.ExecModeCheck {
193186
//ctx.GasMeter().RefundGas(ctx.GasMeter().GasConsumed(), "Walkin it back")

x/structs/keeper/msg_server_struct_build_complete.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ func (k msgServer) StructBuildComplete(goCtx context.Context, msg *types.MsgStru
3232
return &types.MsgStructStatusResponse{}, types.NewObjectNotFoundError("struct", msg.StructId)
3333
}
3434

35-
if structure.GetOwner().IsHalted() {
36-
return &types.MsgStructStatusResponse{}, types.NewPlayerHaltedError(structure.GetOwnerId(), "struct_build_complete").WithStruct(msg.StructId)
37-
}
38-
3935
if structure.IsBuilt() {
4036
//structure.GetOwner().Discharge()
4137
//structure.GetOwner().Commit()

x/structs/keeper/msg_server_struct_build_initiate.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,22 @@ func (k msgServer) StructBuildInitiate(goCtx context.Context, msg *types.MsgStru
3535
return &types.MsgStructStatusResponse{}, permissionError
3636
}
3737

38-
if owner.IsHalted() {
39-
return &types.MsgStructStatusResponse{}, types.NewPlayerHaltedError(msg.PlayerId, "struct_build_initiate")
40-
}
41-
4238
// Load the Struct Type
43-
structType, structTypeFound := k.GetStructType(ctx, msg.StructTypeId)
39+
structType, structTypeFound := cc.GetStructType(msg.StructTypeId)
4440
if !structTypeFound {
4541
return &types.MsgStructStatusResponse{}, types.NewObjectNotFoundError("struct_type", "").WithIndex(msg.StructTypeId)
4642
}
4743

4844
// Check that the player can build more of this type of Struct
49-
if (structType.GetBuildLimit() > 0) {
50-
if (owner.GetBuiltQuantity(msg.StructTypeId) >= structType.GetBuildLimit()) {
51-
owner.Discharge()
52-
return &types.MsgStructStatusResponse{}, types.NewPlayerPowerError(owner.GetPlayerId(), "capacity_exceeded").WithCapacity(structType.GetBuildLimit(), owner.GetBuiltQuantity(msg.StructTypeId))
45+
if (structType.GetStructType().BuildLimit > 0) {
46+
if (owner.GetBuiltQuantity(msg.StructTypeId) >= structType.GetStructType().BuildLimit) {
47+
return &types.MsgStructStatusResponse{}, types.NewPlayerPowerError(owner.GetPlayerId(), "capacity_exceeded").WithCapacity(structType.GetStructType().BuildLimit, owner.GetBuiltQuantity(msg.StructTypeId))
5348
}
5449
}
5550

5651
// Check Player Charge
57-
if (owner.GetCharge() < structType.BuildCharge) {
58-
err := types.NewInsufficientChargeError(owner.GetPlayerId(), structType.BuildCharge, owner.GetCharge(), "build").WithStructType(msg.StructTypeId)
59-
owner.Discharge()
52+
if (owner.GetCharge() < structType.GetStructType().BuildCharge) {
53+
err := types.NewInsufficientChargeError(owner.GetPlayerId(), structType.GetStructType().BuildCharge, owner.GetCharge(), "build").WithStructType(msg.StructTypeId)
6054
return &types.MsgStructStatusResponse{}, err
6155
}
6256

@@ -66,21 +60,17 @@ func (k msgServer) StructBuildInitiate(goCtx context.Context, msg *types.MsgStru
6660
}
6761

6862

69-
if !owner.CanSupportLoadAddition(structType.BuildDraw) {
70-
owner.Discharge()
71-
return &types.MsgStructStatusResponse{}, types.NewPlayerPowerError(owner.GetPlayerId(), "capacity_exceeded").WithCapacity(structType.BuildDraw, owner.GetAvailableCapacity())
63+
if !owner.CanSupportLoadAddition(structType.GetStructType().BuildDraw) {
64+
return &types.MsgStructStatusResponse{}, types.NewPlayerPowerError(owner.GetPlayerId(), "capacity_exceeded").WithCapacity(structType.GetStructType().BuildDraw, owner.GetAvailableCapacity())
7265
}
7366

74-
75-
k.logger.Info("Struct Materializing", "structType", structType.Type, "ambit", msg.OperatingAmbit, "slot", msg.Slot)
76-
structure, err := k.InitiateStruct(ctx, msg.Creator, owner, &structType, msg.OperatingAmbit, msg.Slot)
67+
k.logger.Info("Struct Materializing", "structType", structType.GetStructType().Type, "ambit", msg.OperatingAmbit, "slot", msg.Slot)
68+
structure, err := cc.InitiateStruct(msg.Creator, owner, structType, msg.OperatingAmbit, msg.Slot)
7769
if (err != nil) {
7870
return &types.MsgStructStatusResponse{}, err
7971
}
80-
cc.RegisterStruct(&structure)
8172

8273
owner.Discharge()
8374

84-
8575
return &types.MsgStructStatusResponse{Struct: structure.GetStruct()}, nil
8676
}

x/structs/keeper/msg_server_struct_deactivate.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,15 @@ func (k msgServer) StructDeactivate(goCtx context.Context, msg *types.MsgStructD
2626
return &types.MsgStructStatusResponse{}, permissionError
2727
}
2828

29-
if structure.GetOwner().IsHalted() {
30-
return &types.MsgStructStatusResponse{}, types.NewPlayerHaltedError(structure.GetOwnerId(), "struct_deactivate").WithStruct(msg.StructId)
31-
}
32-
3329
if !structure.LoadStruct(){
3430
return &types.MsgStructStatusResponse{}, types.NewObjectNotFoundError("struct", msg.StructId)
3531
}
3632

3733
if !structure.IsBuilt() {
38-
structure.GetOwner().Discharge()
3934
return &types.MsgStructStatusResponse{}, types.NewStructStateError(msg.StructId, "building", "built", "deactivate")
4035
}
4136

4237
if structure.IsOffline() {
43-
structure.GetOwner().Discharge()
4438
return &types.MsgStructStatusResponse{}, types.NewStructStateError(msg.StructId, "offline", "online", "deactivate")
4539
}
4640

x/structs/keeper/msg_server_struct_defense_clear.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,17 @@ func (k msgServer) StructDefenseClear(goCtx context.Context, msg *types.MsgStruc
3434
return &types.MsgStructStatusResponse{}, types.NewObjectNotFoundError("struct", msg.DefenderStructId)
3535
}
3636

37-
if structure.GetOwner().IsHalted() {
38-
return &types.MsgStructStatusResponse{}, types.NewPlayerHaltedError(structure.GetOwnerId(), "defense_clear").WithStruct(msg.DefenderStructId)
39-
}
40-
4137
if structure.IsOffline() {
42-
structure.GetOwner().Discharge()
4338
return &types.MsgStructStatusResponse{}, types.NewStructStateError(msg.DefenderStructId, "offline", "online", "defense_clear")
4439
}
4540

4641
if !structure.IsCommandable() {
47-
structure.GetOwner().Discharge()
4842
return &types.MsgStructStatusResponse{}, types.NewFleetCommandError(structure.GetStructId(), "no_command_struct")
4943
}
5044

5145
// Check Player Charge
5246
if (structure.GetOwner().GetCharge() < structure.GetStructType().DefendChangeCharge) {
5347
err := types.NewInsufficientChargeError(structure.GetOwnerId(), structure.GetStructType().DefendChangeCharge, structure.GetOwner().GetCharge(), "defend").WithStructType(structure.GetStructType().Id)
54-
structure.GetOwner().Discharge()
5548
return &types.MsgStructStatusResponse{}, err
5649
}
5750

@@ -61,7 +54,6 @@ func (k msgServer) StructDefenseClear(goCtx context.Context, msg *types.MsgStruc
6154

6255
protectedStructIndex := k.GetStructAttribute(ctx, GetStructAttributeIDByObjectId(types.StructAttributeType_protectedStructIndex, msg.DefenderStructId))
6356
if (protectedStructIndex == 0) {
64-
structure.GetOwner().Discharge()
6557
return &types.MsgStructStatusResponse{}, types.NewStructStateError(msg.DefenderStructId, "not_defending", "defending", "defense_clear")
6658
}
6759
protectedStructId := GetObjectID(types.ObjectType_struct, protectedStructIndex)

x/structs/keeper/msg_server_struct_defense_set.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,17 @@ func (k msgServer) StructDefenseSet(goCtx context.Context, msg *types.MsgStructD
4343
return &types.MsgStructStatusResponse{}, types.NewObjectNotFoundError("struct", msg.DefenderStructId)
4444
}
4545

46-
if structure.GetOwner().IsHalted() {
47-
return &types.MsgStructStatusResponse{}, types.NewPlayerHaltedError(structure.GetOwnerId(), "defense_set").WithStruct(msg.DefenderStructId)
48-
}
49-
5046
if structure.IsOffline() {
51-
structure.GetOwner().Discharge()
5247
return &types.MsgStructStatusResponse{}, types.NewStructStateError(msg.DefenderStructId, "offline", "online", "defense_set")
5348
}
5449

5550
if !structure.IsCommandable() {
56-
k.DischargePlayer(ctx, structure.GetOwnerId())
5751
return &types.MsgStructStatusResponse{}, types.NewFleetCommandError(structure.GetStructId(), "no_command_struct")
5852
}
5953

6054
// Check Player Charge
6155
if (structure.GetOwner().GetCharge() < structure.GetStructType().DefendChangeCharge) {
6256
err := types.NewInsufficientChargeError(structure.GetOwnerId(), structure.GetStructType().DefendChangeCharge, structure.GetOwner().GetCharge(), "defend").WithStructType(structure.GetStructType().Id)
63-
structure.GetOwner().Discharge()
6457
return &types.MsgStructStatusResponse{}, err
6558
}
6659

@@ -99,11 +92,9 @@ func (k msgServer) StructDefenseSet(goCtx context.Context, msg *types.MsgStructD
9992
}
10093

10194
if (!inRange) {
102-
structure.GetOwner().Discharge()
10395
return &types.MsgStructStatusResponse{}, types.NewStructLocationError(structure.GetStructType().Id, "", "not_in_range").WithStruct(structure.GetStructId()).WithLocation("struct", msg.ProtectedStructId)
10496
}
10597

106-
10798
k.SetStructDefender(ctx, msg.ProtectedStructId, protectedStructure.Index, structure.GetStructId())
10899

109100
structure.GetOwner().Discharge()

0 commit comments

Comments
 (0)