This file is indexed.

/usr/lib/games/solarwolf/gamenews.py is in solarwolf 1.5-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
"""Game news page handler, part of SOLARWOLF."""

import math, os, threading, re
import urllib, tempfile, shutil
import pygame, pygame.font
from pygame.locals import *
import game
import gfx, snd, txt
import input
import gameplay
import webbrowser
import objbox

images = []
fonts = []
downimgs = []
news_downloaded = 0
ship = None


Options = [
"Main Menu",
"Download News",
"Visit Website",
]


def load_game_resources():
    global images, fonts, downimgs, ship
    img = gfx.load('menu_news_on.png')
    r = img.get_rect().move(10, 10)
    images.append((img, r))

    img = gfx.load('download.png')
    downimgs = gfx.animstrip(img, img.get_width()/2)
    for i in ('downerror', 'newversion', 'downok'):
        img = gfx.load(i+'.gif')
        downimgs.append(img)

    fonts.append((txt.Font(None, 36, italic=1), (150, 150, 200)))
    fonts.append((txt.Font(None, 22), (120, 120, 250)))
    fonts.append((txt.Font(None, 28), (120, 120, 250)))

    ship = pygame.transform.rotate(gfx.load('ship-up.png'), -90)

    snd.preload('select_choose', 'startlife', 'levelskip')


def downloadfunc(gamenews):
    global news_downloaded
    try:
        news = urllib.urlopen(game.news_url).readlines()
    except:
        gamenews.downcur = 3
        return
    gamenews.downcur = 0
    try:
        tag = re.compile('<.*>\n*')
        newsfilename = game.make_dataname('news')
        f = open(newsfilename, 'w')
        for line in news:
            l = re.sub(tag, '', line)
            if l:
                f.write(l.rstrip() + os.linesep)
        f.close()
        gamenews.success = 1
        news_downloaded = 1
    except (IOError, OSError):
        gamenews.downcur = 3



class GameNews:
    def __init__(self, prevhandler):
        global news_downloaded
        news_downloaded = 0
        self.prevhandler = prevhandler
        self.images = images
        self.imgs = []
        self.boxes = []
        self.thread = None
        self.newsversion = "0.0"
        self.loadnews()
        self.success = 0
        self.downimgs = downimgs
        self.downloadpos = 660, 10
        self.clocks = 0
        self.downcur = 0
        self.lastdownrect = None

        self.shipimage = [ship, ship.get_rect()]

        self.done = 0
        self.aborted = 0
        self.linesize = 60
        self.current = 0
        self.gamelist = []
        self.buildlist()
        self.shipmovex = 20
        self.shipmovey = 14
        self.moveto(self.gamelist[0][1])
        self.tempwindowed = 0
        self.launchthebrowser = 0



    def starting(self):
        pass
        #self.download_start()

    def quit(self):
        if self.tempwindowed:
            game.display = 1
            gfx.switchfullscreen()
        game.handler = self.prevhandler
        self.done = 1


    def makebadnews(self, title, message):
        t = fonts[1][0].text(fonts[1][1], title, (100, 200), 'topleft')
        self.imgs.append(t)
        t = fonts[0][0].text(fonts[1][1], message, (140, 235), 'topleft')
        self.imgs.append(t)


    def rendertext(self, font, text):
        return fonts[font][0].text(fonts[font][1], text)


    def loadnews(self):
        self.cleartext()
        self.imgs = []
        self.boxes = []
        newsfilename = game.make_dataname('news')
        if not os.path.isfile(newsfilename):
            newsfilename = game.get_resource('news')
        if os.path.isfile(newsfilename):
            news = open(newsfilename).readlines()[2:]
            if not news:
                self.makebadnews(' ', 'Invalid News File')
                return
            self.newsversion = news[0].split()[-1]
            newsitems = []
            title = date = None
            body = []
            for line in news[2:]:
                line = line.rstrip()
                if not line:
                    if title: newsitems.append((title, date, body))
                    title = date = None
                    body = []
                elif not title: title = line
                elif not date: date = line
                else: body.append(line)
            top = 150
            for t, d, body in newsitems:
                self.boxes.append(objbox.Box((28, top+3), 1))
                self.boxes[-1].rotspeed = 2.0
                self.boxes[-1].rotate = 0.0
                text, r = self.rendertext(0, t)
                trect = r.move(60, top)
                self.imgs.append((text, trect))
                text, r = self.rendertext(1, d)
                r = r.move(trect.right + 25, top+10)
                self.imgs.append((text, r))
                top = trect.bottom
                for b in body:
                    text, r = self.rendertext(2, b)
                    r = r.move((100, top))
                    top = r.bottom
                    self.imgs.append((text, r))
                top += 24
        else:
            self.makebadnews(' ', 'Cannot Download News')


    def download_start(self):
        if not self.thread:
            self.success = 0
            thread = threading.Thread(None, downloadfunc, 'FETCHNEWS', [self])
            self.downcur = 1
            thread.start()
            self.thread = thread
            snd.play('startlife')


    def download_finished(self):
        self.thread = None
        snd.play('levelskip')
        self.loadnews()


    def moveto(self, pos):
        self.shippos = pos[0], pos[1]


    def input(self, i):
        if self.done:
            return
        if i.release:
            return

        if i.translated == input.ABORT:
            self.aborted = 1
            self.done = 1
            snd.play('select_choose')
            self.quit()
        if i.translated == input.PRESS:
            return self.pressed()

        if i.translated in (input.DOWN, input.UP):
            if i.translated == input.DOWN:
                self.current = (self.current+1) % len(self.gamelist)
            else:
                self.current = (self.current-1) % len(self.gamelist)
            snd.play('select_move')
            x = self.gamelist[self.current][1].left
            y = self.gamelist[self.current][1].top
            self.moveto((x, y))
            self.buildlist()


    def event(self, e):
        pass

    def cleartext(self):
        for i in self.imgs:
            r = i[1]
            self.background(r)
            gfx.dirty(r)


    def run(self):
        self.clocks += 1
        self.cleartext()

        if self.thread and (not self.thread.isAlive() and self.success):
            self.download_finished()

        clearme = None
        if self.lastdownrect:
            gfx.dirty(self.background(self.lastdownrect))
            clearme = self.lastdownrect
            self.lastdownrect = None

        r = self.background(self.shipimage[1])
        gfx.dirty(r)

        gfx.updatestars(self.background, gfx)

        if not self.done:
            for img, r in self.images:
                gfx.dirty(gfx.surface.blit(img, r))
            downimg, downrect = self.downimg()
            if downimg:
                self.lastdownrect = gfx.surface.blit(downimg, downrect)
                gfx.dirty2(self.lastdownrect, clearme)

            for text, pos in self.imgs:
                gfx.surface.blit(text, pos)
        else:
            for img, r in self.images:
                gfx.dirty(self.background(r))
            gfx.dirty(clearme)

        if not self.done:
            self.drawlist()
            self.moveship()
            r = gfx.surface.blit(self.shipimage[0], self.shipimage[1])
            gfx.dirty(r)
            for b in self.boxes:
                b.erase(self.background)
                b.tick(1.0)
                b.draw(gfx)
        else:
            #game.handler = self.prevhandler
            for b in self.boxes:
                b.erase(self.background)
            self.clearlist()

        if self.launchthebrowser:
            #we do it like this so the window can get
            #unfullscreened and not minimized on windows
            self.launchthebrowser -= 1
            if not self.launchthebrowser:
                webbrowser.open(game.site_url, 1, 1)


    def downimg(self):
        if not self.downcur:
            if self.newsversion > game.version:
                img = self.downimgs[3]
                r = img.get_rect()
                r.midtop = self.downloadpos
                return img, r
            elif news_downloaded:
                img = self.downimgs[4]
                r = img.get_rect().move(self.downloadpos)
                return img, r
            else:
                return None, None
        if self.downcur == 3:
            img = self.downimgs[2]
        else:
            self.downcur = (self.clocks / 8) % 2 + 1
            img = self.downimgs[self.downcur-1]
        return img, img.get_rect().move(self.downloadpos)


    def background(self, area):
        return gfx.surface.fill((0, 0, 0), area)


    def buildlist(self):
        clr = 220, 230, 240
        clr2 = 140, 150, 160
        offsetx, offsety = 240, 30
        self.clearlist()
        font = fonts[0][0]
        self.gamelist = []
        cur = 0
        for opt in Options:
            if self.current == cur:
                c = clr
            else:
                c = clr2
            imgpos = font.text(c, opt, (offsetx, offsety), "midleft")
            self.gamelist.append(imgpos)
            offsety += 33
            cur += 1


    def clearlist(self):
        for o in self.gamelist:
            gfx.dirty(self.background(o[1]))
        for b in self.boxes:
            b.dead = 1
            b.erase(self.background)

    def drawlist(self):
        for o in self.gamelist:
            gfx.dirty(gfx.surface.blit(*o))

    def moveship(self):
        pos = list(self.shipimage[1].topright)
        if pos[0] + self.shipmovex < self.shippos[0]:
            pos[0] += self.shipmovex
        elif pos[0] < self.shippos[0]:
            pos[0] = self.shippos[0]

        if pos[0] - self.shipmovex > self.shippos[0]:
            pos[0] -= self.shipmovex
        elif pos[0] > self.shippos[0]:
            pos[0] = self.shippos[0]

        if pos[1] + self.shipmovey < self.shippos[1]:
            pos[1] += self.shipmovey
        elif pos[1] < self.shippos[1]:
            pos[1] = self.shippos[1]

        if pos[1] - self.shipmovey > self.shippos[1]:
            pos[1] -= self.shipmovey
        elif pos[1] > self.shippos[1]:
            pos[1] = self.shippos[1]

        self.shipimage[1].topright = pos


    def pressed(self):
        pref = Options[self.current]
        snd.play('select_choose')
        val = Options[self.current].split()[0].lower()
        getattr(self, "do_"+val)()


    def do_main(self): #Main Menu
        self.quit()

    def do_download(self): #Download News
        self.download_start()

    def do_visit(self): #Visit Website
        if game.display: #fullscreen
            self.tempwindowed = 1
            game.display = 0
            gfx.switchfullscreen()
        self.launchthebrowser = 2 #funny windows workaround