SGI Screen Lock program (QUERY)
Brent Bates ViGYAN AAD/TAB
blbates at AERO36.LARC.NASA.GOV
Mon Apr 1 23:04:20 AEST 1991
I saw several version of one posted a while back and I picked up what I
thought looked the best. I use it regularly and it seems to work ok.
I have made some changes to it. At the moment it has a 3D "bouncing"
ball while the screen is locked. What I would really like instead of the
ball is the game of "Life" like on Suns, however have the SGI logo instead
Suns for the "microbes." I am enclosing my version below. If any one has
a simple game of "Life" that could be easily add to what I have please let
me know. I compile it with:
cc -p0 -O3 -Olimit 2048 -o lockscreen lockscreen.c -s -x -lsphere -lc_s
-lgl_s -lm
------------------------- Cut here ------------------------------
#include <sys/types.h>
#include <gl.h>
#include <ctype.h>
#include <device.h>
#include <stdio.h>
#include <pwd.h>
#include <sys/fcntl.h>
#include <gl/sphere.h>
#define MAXLIN 81
extern char * cuserid();
extern struct passwd * getpwnam();
int r_hold = 0; /* right button pressed/released */
int m_hold = 0; /* middle button pressed/released */
int l_hold = 0; /* left button pressed/released */
int xval,yval; /* screen position of valuator */
int stop = 0; /* stop button chosen */
int dummy = 1; /* current character number */
/* bounce parameters */
#define XMIN 0 /* XMIN, ... define the region of the */
#define YMIN 0 /* screen where the ball bounces. */
#define ZMIN 0 /* XMIN, ... define the region of the */
#define XMAX XMAXSCREEN
#define YMAX YMAXSCREEN
#define ZMAX XMAXSCREEN*50
long xvelocity=11,yvelocity=6,zvelbase=1,zvelocity,radius=40;
long xpos=XMAX/2,ypos=YMAX/2,zpos;
/* ************************************************ */
/* ************************************************ */
FILE *fid;
int il,jl;
/* static char tname[] = "root"; */
char tname[L_cuserid+1];
char *string[MAXLIN],stest[MAXLIN];
char key[3], rkey[3];
char pwd[9];
char dwd[9];
char name[L_cuserid+1];
char paswd[14], rpaswd[14];
char crywd[14];
/* ************************************************ */
/* ************************************************ */
/*-------------------------------------------------------------*/
/* */
/* main - Program main initialzation and main loop */
/* */
/*-------------------------------------------------------------*/
main()
{
long queued;
initialize();
qreset();
while( !stop )
{
pushmatrix();
color(0);
clear();
if(qtest()){
queued=qread(&dummy);
if( queued == KEYBD || queued == LEFTMOUSE ||
queued == MIDDLEMOUSE || queued == RIGHTMOUSE ) checklock1();
}
bounce();
swapbuffers();
popmatrix();
}
gexit();
}
/* ****************************************************************** */
/* ****************************************************************** */
initialize()
{
extern char * ttyname();
extern long zpos,radius;
struct passwd * pwd;
char * tty;
tty = ttyname(0);
if (strcmp(tty, "/dev/console"))
{
printf ("Access only allowed from console\n");
exit(1);
}
if (!cuserid(tname)) strcpy (tname, "root");
pwd = getpwnam (tname);
if (! pwd)
{
printf ("Who are you?\n");
exit (1);
}
strcpy (name, pwd->pw_name);
strcpy (paswd, pwd->pw_passwd);
key[0] = paswd[0];
key[1] = paswd[1];
key[2] = '\0';
pwd = getpwnam ("root");
if (! pwd)
{
printf ("Why is there no root?!\n");
exit (1);
}
strcpy (rpaswd, pwd->pw_passwd);
rkey[0] = rpaswd[0];
rkey[1] = rpaswd[1];
rkey[2] = '\0';
prefposition(0,1279,0,1023);
noborder();
winopen("window_lock");
winposition(0,1279,0,1023);
winconstraints();
doublebuffer();
multimap();
gconfig();
qdevice(KEYBD);
qdevice(LEFTMOUSE);
qdevice(MIDDLEMOUSE);
qdevice(RIGHTMOUSE);
qdevice(REDRAW);
setmap(2);
mapcolor(0,000,000,000); /* black */
mapcolor(1,255,255,255); /* white */
mapcolor(2,120,200,255); /* sky */
mapcolor(3,100,100,100); /* very dark grey */
mapcolor(4,150,200,255); /* pale blue */
mapcolor(5,255,155,155); /* pale red */
mapcolor(6,050,200,050); /* button active */
mapcolor(7,000,100,000); /* button not active */
mapcolor(8,155,000,050); /* dark red */
mapcolor(9,230,160,050); /* ground*/
mapcolor(10,255,140,000); /* yellow */
mapcolor(11,000,130,000); /* green */
mapcolor(12,050,000,255); /* blue */
mapcolor(13,255,000,030); /* red */
mapcolor(14,120,120,120); /* dark grey */
/* mapcolor(14,150,150,150);*/ /* dark grey */
mapcolor(15,255,255,255); /* white */
viewport(XMIN, XMAX, YMIN, YMAX);
frontbuffer(FALSE);
zpos=radius+1;
sphmode(SPH_TESS,SPH_BARY);
sphmode(SPH_HEMI,TRUE);
sphmode(SPH_PRIM,SPH_LINE);
} /* end initialize */
/* ****************************************************************** */
/* ****************************************************************** */
checklock1()
{
int c; /* one character of input */
int i; /* counter */
int ok;
int index;
long devid;
long savid;
long textid;
short test;
char dummy = '*';
ortho2(XMIN-0.5,XMAX+0.5,YMIN-0.5,YMAX+0.5); /* define clear the textport */
lookat(0.0,0.0,1.0,0.0,0.0,0.0,0.0);
setmap(2);
devid=513;
qreset();
color(3);
clear();
color(0);
linewidth(4);
move2(440.,562.);
draw2(740.,562.);
draw2(740.,462.);
draw2(440.,462.);
draw2(440.,562.);
color(12);
linewidth(2);
cmov2i(500,540);
charstr( "ENTER PASSWORD " ); /* get user input from textport */
cmov2i(500,525);
charstr( ":>>" ); /* get user input from textport */
swapbuffers();
i=0;
while(i < 9)
{
color(3);
clear();
color(0);
linewidth(4);
move2(440.,562.);
draw2(740.,562.);
draw2(740.,462.);
draw2(440.,462.);
draw2(440.,562.);
color(12);
linewidth(2);
cmov2i(500,540);
charstr( "ENTER PASSWORD " ); /* get user input from textport */
cmov2i(500,525);
charstr( ":>>" ); /* get user input from textport */
/* printf("token = %d value = %d \n",devid,test);*/
if( (devid=qread(&test)) == KEYBD )
{
if(i < 9 && test != 13)
{
c = test;
if ( test != 8 )
{
pwd[i] = test;
dwd[i] = dummy;
pwd[(i) + 1] = '\0';
dwd[(i) + 1] = '\0';
i++;
}
else
{
color(12);
linewidth(2);
cmov2i(500,540);
charstr( "ENTER PASSWORD " );
cmov2i(500,525);
charstr( ":>>" );
i=i--;
if(i<0)i=0;
pwd[i] = '\0';
dwd[i] = '\0';
}/* end of test = 8 */
cmov2i(540,525);
/* charstr(pwd); */
charstr(dwd);
}/* end of first i < 9 && test != 13 */
else
{
i = 10;
strcpy(crywd,crypt(pwd,key));
if( !strcmp(tname,name))
{
ok = !strcmp(crywd,paswd);
if (!ok) /* If not ok, check for the root password */
{
strcpy (crywd, crypt(pwd,rkey));
ok = !strcmp(crywd,rpaswd);
}
if( ok )
{
frontbuffer(TRUE);
color(3);
clear();
color(12);
linewidth(2);
cmov2i(500,525);
charstr("PASSWORD MATCHES OK");
sleep(2);
frontbuffer(TRUE);
color(0);
clear();
color(1);
linewidth(2);
cmov2i(500,540);
charstr( " YOU MAY CONTINUE ");
sleep(2);
exit();
}
else
{
frontbuffer(TRUE);
color(3);
clear();
color(12);
linewidth(2);
cmov2i(500,540);
charstr("PASSWORD FAILED GET HELP");
sleep(2);
frontbuffer(FALSE);
color(3);
clear();
swapbuffers();
color(3);
clear();
}
}
}/* endif i && test */
}/* endif devid */
swapbuffers();
}/* end while */
qreset();
}
/* bounce.c */
bounce()
{
extern long xpos,ypos,zpos;
extern long xvelocity,yvelocity,zvelocity,radius;
float xposf,yposf,zposf,params[4];
xposf=XMAX;
yposf=YMAX;
perspective(90,xposf/yposf,-xposf,xposf);
lookat(xposf/2.0,yposf/2.0,-xposf*4.0,xposf/2.0,yposf/2.0,0.0,0.0);
color(1);
/* movei(0,0,ZMAX);
drawi(XMAX,0,ZMAX);
drawi(XMAX,YMAX,ZMAX);
drawi(0,YMAX,ZMAX);
drawi(0,0,ZMAX);
drawi(0,0,0);
drawi(XMAX,0,0);
drawi(XMAX,YMAX,0);
drawi(0,YMAX,0);
drawi(0,0,0);
movei(XMAX,0,0);
drawi(XMAX,0,ZMAX);
movei(0,YMAX,0);
drawi(0,YMAX,ZMAX);
movei(XMAX,YMAX,0);
drawi(XMAX,YMAX,ZMAX); */
xpos += xvelocity;
ypos += yvelocity;
zpos += zvelocity;
if (xpos > XMAX - radius ||
xpos < XMIN + radius) {
xpos -= xvelocity;
xvelocity = -xvelocity;
}
if (ypos > YMAX - radius ||
ypos < YMIN + radius) {
ypos -= yvelocity;
yvelocity = -yvelocity;
}
if (zpos > ZMAX - radius ||
zpos < ZMIN + radius) {
zpos -= zvelocity;
zvelbase = -zvelbase;
}
color(2);
/* circfi(xpos, ypos, radius);*/
xposf=xpos;
yposf=ypos;
zposf=zpos;
zvelocity=zvelbase*(1.0+200.0*zposf/((float)ZMAX));
params[0]=xposf;
params[1]=yposf;
params[2]=zposf;
params[3]=(float) radius;
sphdraw(params);
}
------------------------- Cut here ------------------------------
Brent L. Bates
NASA-Langley Research Center
M.S. 361
Hampton, Virginia 23665-5225
Phone:(804) 864-2854 FAX:(804) 864-6792
E-mail: blbates at aero36.larc.nasa.gov or blbates at aero8.larc.nasa.gov
More information about the Comp.sys.sgi
mailing list