File: xnetserv-old.tcl

package info (click to toggle)
netmaze 0.81+jpg0.82-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,208 kB
  • ctags: 912
  • sloc: ansic: 8,277; tcl: 1,223; makefile: 60; sh: 26
file content (426 lines) | stat: -rw-r--r-- 11,537 bytes parent folder | download | duplicates (5)
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/usr/bin/wish -f

# NOTE: Tcl/Tk or C on some Sun machines seems to be broken in that it
# requres flush calls after every puts when the output is being piped to
# another program (as it is here).  That is why there are flush calls all
# over in this program.

##### SET UP PROCEDURES

proc unimplemented {} {
  toplevel .u
  label .u.msg -text "This function is not yet implemented."
  pack .u.msg
  button .u.b -text "OK" -command {
    destroy .u
    return 0
  }
  pack .u.b
  wm title .u "xnetserv: unimplemented function"
}

proc playerbox {id} {
  global ids teams names allplayers
  toplevel .players.${id}.dlgbox
  label .players.${id}.dlgbox.l -text "Player $names($id), id $id.\n\
    Select Dismiss below to close this box.\n\
    Select Terminate to kick this player out\n\
    of the game."
  button .players.${id}.dlgbox.b1 -text "Dismiss" -command "\
    destroy .players.$id.dlgbox"
  button .players.${id}.dlgbox.b2 -text "Terminate" -command "\
    destroy .players.$id.dlgbox;\
    puts \"5 $id\";\
    flush stdout"
  pack .players.${id}.dlgbox.l .players.${id}.dlgbox.b1 \
    .players.${id}.dlgbox.b2
  wm title .players.${id}.dlgbox "xnetserv: info on $names($id) ($id)"
}

proc destroymainmenu {} {
  destroy .option1 .option2 .players .misc .options .msg
}

proc sethelp {message} {
  global helpmsg helpon
  # Sets help message, if possible....
  if {$helpon} {
    if {$helpmsg!=$message} {
      set helpmsg $message
    }
  }
}
  
proc addplayerfunc {name id addvars} {
  # allplayers is a list containing all unique IDs.
  # a unique ID is $id_$name
  global allplayers teams names ids \
    isgip numplayers
  if {$addvars} {
    # ONLY add to the vars if this is a NEW creation
    lappend allplayers ${id}
    set names(${id}) $name
    set ids(${id}) $id
    incr numplayers
    set teams(${id}) $id
  }
  if {!$isgip} {
    # Only draw stuff if game is not in progress
    frame .players.${id}


    button .players.${id}.name -text $name -command "playerbox $id"
    bind .players.${id}.name <Any-Motion> {
      sethelp "These buttons let you view info on the player\nor\
        terminate the player's connection to the game."
    }

    entry .players.${id}.team -width 5 -relief sunken -textvariable \
      teams(${id})
    bind .players.${id}.team <Any-Motion> {
      sethelp "This lets you set the team a given player is on.\nAll\
        players with the same team number will be on the same team."
    }
      
      
    pack .players.${id} -in .players -fill x
    pack .players.${id}.name -side left -in .players.${id}
    pack .players.${id}.team -in .players.${id} -side right -padx 1m
  }
}

proc drawplayer {name id} {addplayerfunc $name $id 0}

proc addplayer {name id} {
  addplayerfunc $name $id 1
}

proc rmplayer {name id} {
  global allplayers names ids teams numplayers isgip
  incr numplayers -1
  unset names(${id})
  unset ids(${id})
  unset teams(${id})
  set listindex [lsearch -exact $allplayers ${id}]
  set allplayers [lreplace $allplayers $listindex $listindex]
  unset listindex
  if {!$isgip} {
    destroy .players.${id}
  }
}

proc resetplayers {} {
  global allplayers names ids teams numplayers isgip
  if {$numplayers} {
    unset allplayers
    unset names
    unset ids
    unset teams
  }
  set numplayers 0
  if {!$isgip} {
    destroymainmenu
    mainmenu
    puts "4"
    flush stdout
  }
}

proc startgame {} {
  global isgip
  destroymainmenu
  frame .gip
  label .gip.l -text "Netmaze game is in progress!\nOptions are disabled while\
     game is running.\nThis is Netmaze net protocol version 0.81" -fg white \
     -bg black
  label .gip.lp -image NMLogo
  button .gip.b -text "Abort game" -fg white -bg black -command {
    puts "3"
    flush stdout
  }
  pack .gip -fill both
  pack .gip.l .gip.lp .gip.b -in .gip -fill both
  set isgip 1
}

proc stopgame {} {
  global isgip
  if {$isgip} {
    destroy .gip
  }
  set isgip 0
  mainmenu
}

proc resetteams {} {
  # resets all teams to their defaults, that is, their ids
  global teams ids allplayers numplayers
  if {$numplayers} {
    foreach thisplayer $allplayers {
      set teams($thisplayer) $ids($thisplayer)
    }
  }
}

proc mainmenu {} {
  global newmaze allplayers names ids numplayers teams BEATDIV
  wm title . "xnetserv 0.82"
  
  frame .option1

  # netserv option 1
  
  button .option1.b -text "Load/Reinit maze:" -command {
    puts "1 $newmaze"
    flush stdout
  }
  bind .option1.b <Any-Motion> {
    sethelp "This will load a new maze (if the\nentry\
      box has a filename in it) or reinitialize\nthe\
      current maze."
  }


  entry .option1.e -width 20 -textvariable newmaze
  bind .option1.e <Any-Motion> {
    sethelp "Type the name of a maze to load here,\n\
      or leave blank to use the default maze."
  }


  pack .option1 -side top -padx 1m -pady 1m
  pack .option1.b .option1.e -in .option1 -side left
  
  # netserv option 2
  
  frame .option2

  button .option2.b -text "Start game" -command {
    if {$numplayers} {
      # First....do the options.
      # clear all options
      puts "98"
      flush stdout
      
      if {$BOUNCE} {puts "21"
      flush stdout }
      if {$DECAY} {puts "22"
      flush stdout }
      if {$MULTISHOT} {puts "23"
      flush stdout }
      if {$HURTS2SHOOT} {puts "24"
      flush stdout }
      if {$REPOWERONKILL} {puts "25"
      flush stdout }
      if {$FASTHEAL} {puts "26"
      flush stdout }
      if {$FASTWALK} {puts "27"
      flush stdout }
      if {$CLOAK} {puts "29"
      flush stdout }
      if {$DECSCORE} {puts "32"
      flush stdout }
      if {$TEAMSHOTHURT} {puts "34"
      flush stdout }
      
      if {$BEATDIV>=2} {puts "7"
      flush stdout }
      if {$BEATDIV==4} {puts "7"
      flush stdout }
      
      set startcmd "2"
      # Cycle through teams....
      foreach thisplayer $allplayers {
        lappend cmdlist $teams($thisplayer)
      }
      set i [expr [llength $cmdlist] -1]
      while {$i >= 0} {
        append startcmd " "
        append startcmd [lindex $cmdlist $i]
        incr i -1
      }
      puts $startcmd
      flush stdout
      unset startcmd thisplayer cmdlist i
    }
  }
  bind .option2.b <Any-Motion> {
    sethelp "Start a game with the current settings."
  }

  button .option2.reset -text "Reset teams" -command resetteams
  bind .option2.reset <Any-Motion> {
    sethelp "Reset teams so that everyone is\nplaying\
      individually.  (back to how they were set\nprior\
      to any modification)"
  }
  
  button .option2.refresh -text "Refresh" -command {
    puts "96"
    flush stdout
  }
  bind .option2.refresh <Any-Motion> {
    sethelp "Will refresh xnetserv's team listing in case it somehow got\
             corrupted."
  }

  pack .option2 -side top -padx 1m -pady 1m -side top
  pack .option2.b .option2.reset .option2.refresh -side left -in .option2 -padx 1m
  
  frame .players -relief ridge -borderwidth 4
  frame .players.labels
  label .players.labels.name -text "Players:"
  label .players.labels.team -text "Team:"
  pack .players -side top
  pack .players.labels -side top -in .players -fill x
  pack .players.labels.name -side left -in .players.labels
  pack .players.labels.team -side right -in .players.labels
  
  if {$numplayers} {
    foreach thisplayer $allplayers {
      drawplayer $names($thisplayer) $ids($thisplayer)
    }
  }
  
  ############ THE OPTIONS!
  
  frame .options -relief ridge -borderwidth 4
  frame .options.m
  frame .options.a
  pack .options -side top -fill x
  pack .options.m .options.a -fill x -in .options
  frame .options.m.f1
  frame .options.m.f2
  frame .options.a.f3

  checkbutton .options.m.f1.bounce -text Bounce -variable BOUNCE
  checkbutton .options.m.f1.decay -text Decay -variable DECAY
  checkbutton .options.m.f1.multishot -text "Multi-shot" -variable MULTISHOT
  checkbutton .options.m.f1.hurts2shoot -text "Hurts to shoot" -variable HURTS2SHOOT
  checkbutton .options.m.f1.repoweronkill -text "Repower on kill" -variable REPOWERONKILL
  checkbutton .options.m.f2.fastheal -text "Fast heal" -variable FASTHEAL
  checkbutton .options.m.f2.fastwalk -text "Fast walk" -variable FASTWALK
  checkbutton .options.m.f2.cloak -text "Cloaking" -variable CLOAK
  checkbutton .options.m.f2.decscore -text "Decrease score" -variable DECSCORE
  checkbutton .options.m.f2.teamshothurt -text "Team shots hurt" -variable TEAMSHOTHURT
  
  button .options.a.f3.beatbutton -text "Beat divider" -command {
    if {1==$BEATDIV} {
      set BEATDIV 2
    } elseif {$BEATDIV==2} {
      set BEATDIV 4
    } elseif {$BEATDIV==4} {
      set BEATDIV 1
    }
  }
  label .options.a.f3.beatlabel -textvariable BEATDIV
  
  pack .options.m.f1 .options.m.f2 -side left -fill x
  pack .options.a.f3 -fill x
  pack .options.m.f1.bounce .options.m.f1.decay -in .options.m.f1 -anchor w
  pack .options.m.f1.multishot .options.m.f1.hurts2shoot -in .options.m.f1 -anchor w
  pack .options.m.f1.repoweronkill -in .options.m.f1 -anchor w
  pack .options.m.f2.fastheal -in .options.m.f2 -anchor w
  pack .options.m.f2.fastwalk .options.m.f2.cloak -in .options.m.f2 -anchor w
  pack .options.m.f2.decscore .options.m.f2.teamshothurt -in .options.m.f2 -anchor w
  pack .options.a.f3.beatbutton .options.a.f3.beatlabel -in .options.a.f3 -anchor w -side left
  
  # messages
  
  frame .msg
  pack .msg -side top -fill x
  entry .msg.entry -textvariable MSGSEND
  pack .msg.entry -fill x -in .msg
  bind .msg.entry <Return> {
    set transcmd "97 "
    append transcmd $MSGSEND
    puts $transcmd
    flush stdout
    unset transcmd
  }
  bind .msg.entry <Any-Motion> {
    sethelp "Type a message here and press enter to send\nit\
             to the xterms of all players."
  }
  
  # quit

  frame .misc
    
  button .misc.b -text "Quit xnetserv" -command {
    puts "9"
    flush stdout
    exit
  }
  button .misc.help -text "Online help" -command {
    if {!$helpon} {
      toplevel .help
      label .help.intro -text "xnetserv by John Goerzen\nOnline help\nMove\
        the mouse over any item\nand help will appear here."
      frame .help.m
      label .help.m.l -textvariable helpmsg -relief sunken -borderwidth 4
      button .help.button -text "Dismiss" -command {
        destroy .help
        set helpon 0
      }
      label .help.author -text "E-mail: <jgoerzen@complete.org>"
      wm title .help "xnetserv help"
      set helpon 1
      pack .help.intro
      pack .help.m -fill x
      pack .help.button .help.author
      pack .help.m.l -in .help.m -side left
    }
  }
      
    
  pack .misc -side top -padx 1m -pady 1m -side top
  pack .misc.b .misc.help -side left -in .misc
  
}

proc intro {} {

  wm title . "Welcome to Netmaze!"
  label .li -text "Welcome to Netmaze!  Click below to begin" -bg midnightblue \
   -fg white
  pack .li
  label .l -text "Version 0.82 (0.81 compat)" -bg black -fg red
  . config -bg black
  image create photo NMLogo -file nmlogo.gif
  button .b -image NMLogo  -command {
    destroy .b .li
    destroy .l
    set isgip 0
    . config -bg #d9d9d9
    mainmenu
    return 0 
  }
  pack .b .l
}

# This is it, folks: everything starts here.

set numplayers 0
set isgip 1
set helpon 0
set helpmsg "This is xnetserv by John Goerzen."
# isgip is set to true so that messages don't try to draw on the box.
# When the main box appears, isgip is set to 0.

# default options

set BOUNCE 0
set DECAY 0
set HURTS2SHOOT 0
set MULTISHOT 1
set REPOWERONKILL 0
set FASTHEAL 1
set FASTWALK 1
set CLOAK 0
set DECSCORE 0
set TEAMSHOTHURT 0

set BEATDIV 1

intro