ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/highscore.ext
(Generate patch)

Comparing deliantra/server/ext/highscore.ext (file contents):
Revision 1.6 by root, Tue May 4 21:45:42 2010 UTC vs.
Revision 1.7 by root, Sun May 9 22:51:13 2010 UTC

81 $ob->stats->maxgrace, 81 $ob->stats->maxgrace,
82 $ob->uuid, 82 $ob->uuid,
83 int AE::now, 83 int AE::now,
84 ]; 84 ];
85 85
86 cf::async {
87 my $guard = cf::lock_acquire "highscore:check"; 86 my $guard = cf::lock_acquire "highscore:check";
88 87
89 # load hiscore, patch, save hiscore 88 # load hiscore, patch, save hiscore
90 my $hiscore = load_hiscore; 89 my $hiscore = load_hiscore;
91 90
92 cf::get_slot 0.01, 0, "highscore check"; 91 cf::get_slot 0.01, 0, "highscore check";
93 92
94 my ($pre, $ins, $save); 93 my ($pre, $ins, $save);
95 94
96 pop @$hiscore while @$hiscore > $HIGHSCORE_ENTRIES; 95 pop @$hiscore while @$hiscore > $HIGHSCORE_ENTRIES;
97 96
98 # find previous entry, and new position 97 # find previous entry, and new position
99 98
100 for (0 .. $#$hiscore) { 99 for (0 .. $#$hiscore) {
101 $pre //= $_ if $hiscore->[$_][0] eq $score->[0]; 100 $pre //= $_ if $hiscore->[$_][0] eq $score->[0];
102 $ins //= $_ if $hiscore->[$_][2] < $score->[2]; 101 $ins //= $_ if $hiscore->[$_][2] < $score->[2];
103 } 102 }
104 cf::cede_to_tick; # we need an "interruptible" block... 103 cf::cede_to_tick; # we need an "interruptible" block...
105 104
106 my $msg; 105 my $msg;
107 106
108 if (defined $pre) { 107 if (defined $pre) {
109 # we are already in the list 108 # we are already in the list
110 if ($hiscore->[$pre][2] < $score->[2]) { 109 if ($hiscore->[$pre][2] < $score->[2]) {
111 $msg = "T<You beat your last score!>\n\n" 110 $msg = "T<You beat your last score!>\n\n"
112 . $SEP
113 . $HEADER
114 . $SEP
115 . (fmt $ins, $score)
116 . (fmt $pre, $hiscore->[$pre])
117 . $SEP;
118
119 splice @$hiscore, $pre, 1;
120 splice @$hiscore, $ins, 0, $score;
121 $save = 1;
122 } else {
123 $msg = "T<You did not beat your last score.>\n\n"
124 . $SEP
125 . $HEADER
126 . $SEP
127 . (fmt $pre , $hiscore->[$pre])
128 . (fmt undef, $score)
129 . $SEP;
130 }
131 } elsif (defined $ins or @$hiscore < $HIGHSCORE_ENTRIES) {
132 $ins //= @$hiscore;
133
134 $msg = "T<You entered the highscore list!>\n\n"
135 . $SEP 111 . $SEP
136 . $HEADER 112 . $HEADER
137 . $SEP 113 . $SEP
138 . (fmt $ins, $score) 114 . (fmt $ins, $score)
115 . (fmt $pre, $hiscore->[$pre])
139 . $SEP; 116 . $SEP;
140 117
118 splice @$hiscore, $pre, 1;
141 splice @$hiscore, $ins, 0, $score; 119 splice @$hiscore, $ins, 0, $score;
142 $save = 1; 120 $save = 1;
143 } else { 121 } else {
144 $msg = "T<You did not enter the highscore list.>\n\n" 122 $msg = "T<You did not beat your last score.>\n\n"
145 . $SEP 123 . $SEP
146 . $HEADER 124 . $HEADER
147 . $SEP 125 . $SEP
148 . (fmt -1 + (scalar @$hiscore), $hiscore->[-1]) 126 . (fmt $pre , $hiscore->[$pre])
149 . (fmt undef, $score) 127 . (fmt undef, $score)
150 . $SEP; 128 . $SEP;
151 } 129 }
130 } elsif (defined $ins or @$hiscore < $HIGHSCORE_ENTRIES) {
131 $ins //= @$hiscore;
152 132
153 cf::info $msg;#d# remove once working stable 133 $msg = "T<You entered the highscore list!>\n\n"
134 . $SEP
135 . $HEADER
136 . $SEP
137 . (fmt $ins, $score)
138 . $SEP;
154 139
155 $ob->send_msg ($SCORE_CHANNEL => $msg, cf::NDI_CLEAR); 140 splice @$hiscore, $ins, 0, $score;
141 $save = 1;
142 } else {
143 $msg = "T<You did not enter the highscore list.>\n\n"
144 . $SEP
145 . $HEADER
146 . $SEP
147 . (fmt -1 + (scalar @$hiscore), $hiscore->[-1])
148 . (fmt undef, $score)
149 . $SEP;
150 }
156 151
152 cf::info $msg;#d# remove once working stable
153
154 $ob->send_msg ($SCORE_CHANNEL => $msg, cf::NDI_CLEAR);
155
157 if ($save) { 156 if ($save) {
158 save_hiscore $hiscore 157 save_hiscore $hiscore
159 or die "unable to write highscore file: $!"; 158 or die "unable to write highscore file: $!";
160 }
161 }; 159 }
162} 160}
163 161

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines