history
rules
expert advice
online challenge
game source
links
test yourself
board room
the last minute
about us




User.Java source file


import java.net.*;
import java.io.*;
import java.util.*;

public class user
{
String[] name=new String[100];
DataOutputStream[] dout=new DataOutputStream[100];
public String[] adrss=new String[100];
int[] ptn=new int[100];

int nou=-1;

user()
{
for (int i=0;i<100;i++)
{
name[i]="None";
dout[i]=null;
adrss[i]=null;
ptn[i]=-1;
}
};

public void tellAll(String msg) throws Exception
{
sendtoAll("Tell "+msg);
};

public int getNo_of_Users()
{
int i=99;
while ((name[i].equals("None")) & (i>=0))
i--;
return i;
};

public void printOut(String str) {
System.out.println(str);
}

public void sendUsers() throws Exception
{
for (int i=0;i<=nou;i++)
{
if (dout[i]!=null)
{
DataOutputStream dataout=dout[i];
dataout.writeUTF("Noofusers "+nou);
for (int j=0;j<=nou;j++)
{
dataout.writeUTF("Playername "+j+" "+name[j]);
dataout.writeUTF("Playercomb "+j+" "+ptn[j]);
};
dataout.writeUTF("PlayerUpdateOver");
dataout.flush();
};
};

};

public void sendtoAll(String str) throws Exception
{
for (int i=0;i<=nou;i++)
if (dout[i]!=null)
{
dout[i].writeUTF(str);
dout[i].flush();
};
};

public boolean processRequests(String ad, DataInputStream datain, DataOutputStream dataout,int myId){
adrss[myId]=ad;
try {
String req = datain.readUTF();
StringTokenizer t=new StringTokenizer(req);
String command=t.nextToken();

if (command.equals("NEW"))
{
String nn=t.nextToken();

printOut("Incoming request : New Player - "+nn);
printOut("Replying ID: "+Integer.toString(myId));
dataout.writeUTF("ID "+Integer.toString(myId));
name[myId]=nn;
dout[myId]=dataout;
ptn[myId]=-1;
dataout.flush();

nou=getNo_of_Users();
printOut("Number of Users online : "+(getNo_of_Users()+1));

printOut("Transferring player's information ...");

sendUsers();

printOut("Data Transferring completed.");
dataout.writeUTF("Over");
dataout.flush();

return true;
}

if (command.equals("Chat"))
{
String mssg=req.substring(command.length()+1,req.length());
sendtoAll("Chat "+name[myId]+": "+mssg);

return true;
}

if (command.equals("Join"))
{
int player=Integer.parseInt(t.nextToken());
if ((!name[player].equals("None")) && (dout[player]!=null))
{
ptn[myId]=player;
ptn[player]=myId;
sendUsers();
dataout.writeUTF("Opengame");
dataout.flush();
dout[player].writeUTF("Opengame");
dout[player].flush();
printOut("Game opened for "+name[player]+" & "+name[myId]);
};
return true;
};

if (command.equals("Move"))
{
int k=Integer.parseInt(t.nextToken());
if (dout[ptn[myId]]!=null)
{
dout[ptn[myId]].writeUTF("Move "+k);
dout[ptn[myId]].flush();
};
return true;
};

if (command.equals("Endgame"))
{
dataout.writeUTF("Youquitgame");
dataout.flush();
if (dout[ptn[myId]]!=null)
{
dout[ptn[myId]].writeUTF("Closegame");
dout[ptn[myId]].flush();
};
ptn[ptn[myId]]=-1;
ptn[myId]=-1;

sendUsers();

return true;
};

if (command.equals("Bye"))
{
name[myId]="None";
dout[myId]=null;
System.out.println("User "+myId+" - "+name[myId]+" quitted");
sendUsers();
return false;
}
else {
System.out.println("Unknown service requested : "+req);
return true;
}
} catch(Exception ioe) {
System.out.println(ioe.getMessage());
System.out.println("User "+myId+" - "+name[myId]+" quitted");
try
{
if (ptn[myId]!=-1)
{
ptn[ptn[myId]]=-1;
dout[ptn[myId]].writeUTF("Closegame");
};
ptn[myId]=-1;
name[myId]="None";
dout[myId]=null;
sendUsers();
} catch (Exception e) {printOut(e.getMessage());};
return false;
}

}

};

view the source file

By visiting the below links to the source code, you have agreed to our license agreement. The source codes are copyright and if you wish to use the source code or part of the engine of the game, you must obtain weiqi.com permission first. The final decision lies with weiqi.com .

Source for Board.Java

Source for Chess.Java

Source for Client.Java

Source for Server.Java

Source for ServerThread.Java

Source for User.Java

Source for Weiqi.Java

Source for WelcomeDialog.Java

top

©1999. weiqi.com Last updated on 14/08/99