Skip to content

Commit

Permalink
PoW for antispam
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Jan 19, 2025
1 parent 086ffa9 commit 3fe798b
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 132 deletions.
2 changes: 1 addition & 1 deletion atom/atom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace $.$$ {
const land = $.$hyoo_crus_glob.home().land()

const reg = land.Node( $hyoo_crus_atom_ref_to( ()=> $hyoo_crus_atom_vary ) ).Item( '11111111' )
const remote = reg.ensure({ '': $hyoo_crus_rank.get })!
const remote = reg.ensure({ '': $hyoo_crus_rank_read })!

$mol_assert_unique( reg.land(), remote.land() )
$mol_assert_equal( reg.vary()!, remote.ref() )
Expand Down
6 changes: 3 additions & 3 deletions dict/dict.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ namespace $.$$ {
user.Title(null)!.val( 'Jin' )
$mol_assert_equal( user.Title()!.val() ?? '', 'Jin' )

const account = user.Account(null)!.ensure({ '': $hyoo_crus_rank.get })!
const account = user.Account(null)!.ensure({ '': $hyoo_crus_rank_read })!
$mol_assert_equal( user.Account()?.remote() ?? null, account )
$mol_assert_equal( account.User()?.remote() ?? null, null )

account.User(null)!.remote( user )
$mol_assert_equal( account.User()?.remote(), user )

const articles = [
user.Articles(null)!.remote_make({ '': $hyoo_crus_rank.get }),
user.Articles(null)!.remote_make({ '': $hyoo_crus_rank.get }),
user.Articles(null)!.remote_make({ '': $hyoo_crus_rank_read }),
user.Articles(null)!.remote_make({ '': $hyoo_crus_rank_read }),
]
$mol_assert_equal( user.Articles()?.remote_list(), articles )

Expand Down
2 changes: 1 addition & 1 deletion empire/empire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace $.$$ {
const before = start.shift( 'PT-1h' )
const after = start.shift( 'PT1h' )

const pub = { '': $hyoo_crus_rank.get }
const pub = { '': $hyoo_crus_rank_read }
const target = targets.path( [ Place.SPb, Type.Alarm, start ], pub )!.remote_make( pub )!
targets.path( [ Place.SPb, Type.Alarm, after ], pub )!.add( target.ref() )
targets.path( [ Place.SPb, Type.Skip, start ], pub )!.add( target.ref() )
Expand Down
6 changes: 3 additions & 3 deletions flex/field/field.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ namespace $.$$ {

const preset = ( {
private: {},
public: { '': $hyoo_crus_rank.get },
lobby: { '': $hyoo_crus_rank.reg },
orgy: { '': $hyoo_crus_rank.mod },
public: { '': $hyoo_crus_rank_read },
lobby: { '': $hyoo_crus_rank_join( 'just' ) },
orgy: { '': $hyoo_crus_rank_post( 'just' ) },
} as Record< string, $hyoo_crus_rank_preset > )[ rights as any ]

if( preset ) {
Expand Down
2 changes: 1 addition & 1 deletion flex/form/form.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace $.$$ {
@ $mol_mem
kind() {

const land = this.$.$hyoo_crus_glob.home().hall_by( $hyoo_crus_flex_domain, { '': $hyoo_crus_rank.get } )!.land()
const land = this.$.$hyoo_crus_glob.home().hall_by( $hyoo_crus_flex_domain, { '': $hyoo_crus_rank_read } )!.land()
const domain = $hyoo_crus_flex_domain.ensure( land )

return this.node().cast( $hyoo_crus_flex_thing ).Kind()?.remote() ?? domain.Kinds()?.remote_list()[0] ?? null!
Expand Down
23 changes: 15 additions & 8 deletions gift/gift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ namespace $ {
/** Given Rank and Secret */
export class $hyoo_crus_gift extends $hyoo_crus_unit {

rank( next?: $hyoo_crus_rank ) {
rank( next?: typeof $hyoo_crus_rank.Value ) {

if( next !== undefined ) this.uint8( 0, $hyoo_crus_unit_kind.gift )
next = this.uint8( 1, next )
const res = this.uint8( 1, next ) as typeof $hyoo_crus_rank.Value

if( next < $hyoo_crus_rank.nil || next > $hyoo_crus_rank.law ) {
$mol_fail( new RangeError( `Wrong rank ${ next }` ) )
if( res < $hyoo_crus_rank_deny || res > $hyoo_crus_rank_rule ) {
$mol_fail( new RangeError( `Wrong rank ${ res }` ) )
}

return next
return res
}

time( next?: number ) {
Expand Down Expand Up @@ -49,20 +49,27 @@ namespace $ {
kind: this.kind(),
peer: this.peer(),
dest: this.dest().description!,
rank: $hyoo_crus_rank[ this.rank() ],
tier: $hyoo_crus_rank_tier[ this.rank() &~ $hyoo_crus_rank_rate.just ],
work: this.work(),
time: $hyoo_crus_time_dump( this.time() ),
}
}

rank_min() {
return $hyoo_crus_rank( $hyoo_crus_rank_rule | ( $hyoo_crus_rank_rate.just - this.work() ) )
}

[ $mol_dev_format_head ]() {
return $mol_dev_format_span( {} ,
$mol_dev_format_native( this ) ,
' ',
this.peer(),
' 🏅 ',
$mol_dev_format_span( {}, this.dest().description || '_' ),
this.bill().some( v => v ) ? ' 🔐' : ' 📢',
$hyoo_crus_rank[ this.rank() ],
this.bill().some( v => v ) ? ' 🔐' : ' 👀',
$hyoo_crus_rank_tier[ this.rank() &~ $hyoo_crus_rank_rate.just ],
':',
this.rank() & $hyoo_crus_rank_rate.just,
' ',
$mol_dev_format_shade( $hyoo_crus_time_dump( this.time() ) ),
)
Expand Down
12 changes: 6 additions & 6 deletions glob/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ namespace $ {
}

@ $mol_action
static king_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank.get } ) {
static king_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank_read } ) {

const king = this.$.$hyoo_crus_auth.grab()
const colony = ( $mol_wire_sync( $hyoo_crus_land ) as typeof $hyoo_crus_land ).make({ $: this.$ })
colony.auth = $mol_const( king )

if( ( preset[''] ?? $hyoo_crus_rank.nil ) === $hyoo_crus_rank.nil ) {
if( ( preset[''] ?? $hyoo_crus_rank_deny ) === $hyoo_crus_rank_deny ) {
colony.encrypted( true )
}

const self = this.$.$hyoo_crus_auth.current()
colony.give( self, $hyoo_crus_rank.law )
colony.give( self, $hyoo_crus_rank_rule )

for( const key in preset ) colony.give( key ? $hyoo_crus_auth.from( key ) : null, preset[ key ] )

Expand All @@ -49,17 +49,17 @@ namespace $ {
}

/** @deprecated Use `this.$.$hyoo_crus_glob` */
king_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank.get } ) {
king_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank_read } ) {
return this.$.$hyoo_crus_glob.king_grab( preset )
}

@ $mol_action
static land_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank.get } ) {
static land_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank_read } ) {
return this.Land( this.king_grab( preset ).lord() )
}

/** @deprecated Use `this.$.$hyoo_crus_glob` */
land_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank.get } ) {
land_grab( preset : $hyoo_crus_rank_preset = { '': $hyoo_crus_rank_read } ) {
return this.$.$hyoo_crus_glob.land_grab( preset )
}

Expand Down
2 changes: 1 addition & 1 deletion home/home.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace $ {
'Per app profiles'( $ ) {

const base = $.$hyoo_crus_glob.home()
const hall = base.hall_by( $hyoo_crus_dict, { '': $hyoo_crus_rank.get } )!
const hall = base.hall_by( $hyoo_crus_dict, { '': $hyoo_crus_rank_read } )!

$mol_assert_unique( base.land(), hall )

Expand Down
6 changes: 3 additions & 3 deletions land/grab/grab.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace $.$$ {

const preset = ( {
private: {},
public: { '': $hyoo_crus_rank.get },
lobby: { '': $hyoo_crus_rank.reg },
orgy: { '': $hyoo_crus_rank.mod },
public: { '': $hyoo_crus_rank_read },
lobby: { '': $hyoo_crus_rank_join( 'slow' ) },
orgy: { '': $hyoo_crus_rank_post( 'slow' ) },
} as Record< string, $hyoo_crus_rank_preset > )[ rights as any ]

if( preset ) this.grab( preset )
Expand Down
56 changes: 28 additions & 28 deletions land/land.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace $ {

const land = $hyoo_crus_land.make({ $ })
$mol_assert_equal( land.joined_list(), [] )
$mol_assert_equal( land.lord_rank( land.ref() ), $hyoo_crus_rank.law )
$mol_assert_equal( land.lord_rank( land.ref() ), $hyoo_crus_rank_rule )

land.join()
$mol_assert_equal( land.joined_list(), [ land.ref() ] )
Expand All @@ -21,36 +21,36 @@ namespace $ {
const land1 = $hyoo_crus_land.make({ $ })
const land2 = $hyoo_crus_land.make({ $, ref: ()=> land1.ref(), auth: ()=> auth1 })

$mol_assert_equal( land1.lord_rank( land1.ref() ), $hyoo_crus_rank.law )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.get )
$mol_assert_equal( land1.lord_rank( land1.ref() ), $hyoo_crus_rank_rule )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_read )

$mol_assert_fail( ()=> land2.give( auth2, $hyoo_crus_rank.reg ), 'Need reg rank to join' )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.get )
$mol_assert_fail( ()=> land2.give( auth2, $hyoo_crus_rank_join( 'just' ) ), 'Need reg rank to join' )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_read )

land1.give( auth1, $hyoo_crus_rank.get )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.get )
land1.give( auth1, $hyoo_crus_rank_read )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_read )

land1.give( auth1, $hyoo_crus_rank.reg )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.reg )
land1.give( auth1, $hyoo_crus_rank_join( 'just' ) )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_join( 'just' ) )

land1.give( auth1, $hyoo_crus_rank.get )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.get )
land1.give( auth1, $hyoo_crus_rank_read )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_read )

land1.give( auth1, $hyoo_crus_rank.mod )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.mod )
land1.give( auth1, $hyoo_crus_rank_post( 'just' ) )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_post( 'just' ) )

land1.give( auth1, $hyoo_crus_rank.reg )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.reg )
land1.give( auth1, $hyoo_crus_rank_join( 'just' ) )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_join( 'just' ) )

land1.give( auth1, $hyoo_crus_rank.law )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.law )
land1.give( auth1, $hyoo_crus_rank_rule )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_rule )

land1.give( auth1, $hyoo_crus_rank.mod )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank.mod )
land1.give( auth1, $hyoo_crus_rank_post( 'just' ) )
$mol_assert_equal( land1.lord_rank( auth1.lord() ), $hyoo_crus_rank_post( 'just' ) )

land2.apply_unit( land1.delta_unit() )
$mol_assert_equal( land2.lord_rank( auth1.lord() ), $hyoo_crus_rank.mod )
$mol_assert_fail( ()=> land2.give( auth2, $hyoo_crus_rank.reg ), 'Need law rank to change rank' )
$mol_assert_equal( land2.lord_rank( auth1.lord() ), $hyoo_crus_rank_post( 'just' ) )
$mol_assert_fail( ()=> land2.give( auth2, $hyoo_crus_rank_join( 'just' ) ), 'Need law rank to change rank' )

},

Expand All @@ -76,7 +76,7 @@ namespace $ {
$mol_assert_equal( land2.delta_unit().length, 3 )
$mol_assert_equal( land2.delta_unit( face ).length, 1 )

land1.give( auth2, $hyoo_crus_rank.reg )
land1.give( auth2, $hyoo_crus_rank_join( 'just' ) )
land2.apply_unit( land1.delta_unit() )
land2.join()
$mol_assert_equal( land2.delta_unit().length, 5 )
Expand All @@ -86,17 +86,17 @@ namespace $ {
$mol_assert_equal( land2.delta_unit().length, 5 )
$mol_assert_equal( land2.delta_unit( face ).length, 3 )

land1.give( auth2, $hyoo_crus_rank.mod )
land1.give( auth2, $hyoo_crus_rank_post( 'just' ) )
land2.apply_unit( land1.delta_unit() )
land2.post( 'AA222222', '', 'AA333333', new Uint8Array([ 4 ]) )
$mol_assert_equal( land2.delta_unit().length, 6 )
$mol_assert_equal( land2.delta_unit( face ).length, 4 )

land1.give( auth2, $hyoo_crus_rank.reg )
land1.give( auth2, $hyoo_crus_rank_join( 'just' ) )
land2.apply_unit( land1.delta_unit() )
$mol_assert_equal( land2.delta_unit().length, 5 )

land1.give( auth2, $hyoo_crus_rank.get )
land1.give( auth2, $hyoo_crus_rank_read )
land2.apply_unit( land1.delta_unit() )
$mol_assert_equal( land2.delta_unit().length, 4 )

Expand Down Expand Up @@ -181,11 +181,11 @@ namespace $ {

'Land Area inherits rights'( $ ) {

const base = $.$hyoo_crus_glob.land_grab({ '': $hyoo_crus_rank.mod })
const base = $.$hyoo_crus_glob.land_grab({ '': $hyoo_crus_rank_post( 'just' ) })
const area = base.area_make()

$mol_assert_equal( area.lord_rank( area.auth().lord() ), $hyoo_crus_rank.law )
$mol_assert_equal( area.lord_rank( $hyoo_crus_ref( '' ) ), $hyoo_crus_rank.mod )
$mol_assert_equal( area.lord_rank( area.auth().lord() ), $hyoo_crus_rank_rule )
$mol_assert_equal( area.lord_rank( $hyoo_crus_ref( '' ) ), $hyoo_crus_rank_post( 'just' ) )

},

Expand Down
Loading

0 comments on commit 3fe798b

Please sign in to comment.