📄 serverthreadforclient.java
字号:
/*
* ServerThreadForClient.java
*
* Created on 2007年5月6日, 上午2:16
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package 服务器端程序包;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
/**
*
* @author acer5542
*/
public class ServerThreadForClient extends Thread{
private String QQNumber;
private String QQPassword;
private String NickName;
private String TrueName;
private String Sex;
private String Age;
private String LeavingInformation;
private String Icon;
private String Sign;
private String FriendList;
private String OnlineTime;
private String RequestList;
private String ResponseList;
private String GroupList;
private String MyGroup;
private String Message;
private String GroupLeavingMessage;
private Socket clientSocket;
private BufferedReader In;
private PrintWriter Out;
private boolean IsHide=false;
private Identifying Identify;
/** Creates a new instance of ServerThreadForClient */
public ServerThreadForClient(Socket Sot)
{
clientSocket=Sot;
//clientOnLineList=List;
try
{
In=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
catch(IOException e)
{
}
}
public void UpdateOnlineListOn(String FriendList){
String x=null;
StringTokenizer St=new StringTokenizer(FriendList,"#");
while(St.hasMoreTokens()){
x=St.nextToken();
String to=x.substring(1,10);
System.out.println("截得的QQ号码是:"+to);
String r="0E"+QQNumber;
System.out.println(r);
for(int i=0;i<服务器界面.clientOnlineList.GetLength();i++){
if(服务器界面.clientOnlineList.GetMember(i).GetNumber().equals(to)){
PrintWriter out=null;
Socket ToSocket=服务器界面.clientOnlineList.GetMember(i).GetSocket();
try {
out=new PrintWriter(ToSocket.getOutputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
out.println(new String(new StringBuffer(r)));
out.flush();
break;
}
}
}
}
public void UpdateOnlineListOff(String FriendList){
String x=null;
StringTokenizer St=new StringTokenizer(FriendList,"#");
while(St.hasMoreTokens()){
x=St.nextToken();
String to=x.substring(1,10);
System.out.println("截得的QQ号码是:"+to);
String r="2"+QQNumber;
System.out.println(r);
for(int i=0;i<服务器界面.clientOnlineList.GetLength();i++){
if(服务器界面.clientOnlineList.GetMember(i).GetNumber().equals(to)){
PrintWriter out=null;
Socket ToSocket=服务器界面.clientOnlineList.GetMember(i).GetSocket();
try {
out=new PrintWriter(ToSocket.getOutputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
out.println(new String(new StringBuffer(r)));
out.flush();
break;
}
}
}
}
public String TellYouWhoIsOnLine(String FrieList){
String y=null;
String r="0Y";
StringTokenizer St=new StringTokenizer(FrieList,"#");
while(St.hasMoreTokens()){
y=St.nextToken();
String to=y.substring(1,10);
System.out.println("截得的QQ号码是:"+to);
for(int i=0;i<服务器界面.clientOnlineList.GetLength();i++){
if(服务器界面.clientOnlineList.GetMember(i).GetNumber().equals(to)&&!服务器界面.clientOnlineList.GetMember(i).GetState()){
r=r+to+"#";
break;
}
}
}
System.out.println("号码:"+r);
return r;
}
public void run()
{
while(true)
{
try
{
String Information=In.readLine();
if(Information.startsWith("0")) //验证用户名或密码是否正确消息格式为0
{
System.out.println("状态:"+Information.substring(1,2));
if(Information.substring(1,2).equals("1"))
{
IsHide=true;
System.out.println("隐身状态:"+IsHide);
}
QQNumber=Information.substring(2,11);
QQPassword=Information.substring(11);
Identify=new Identifying(QQNumber,QQPassword);
System.out.println(QQNumber);
System.out.println(QQPassword);
if(Identify.IsNumberExistOnline()){ //用户已经登录
String r="E";
Out=new PrintWriter(clientSocket.getOutputStream());
Out.println(new String(new StringBuffer(r)));
Out.flush();
}
else if(!Identify.CheckQQNumber())
{
String r="N"; //号码不存在
Out=new PrintWriter(clientSocket.getOutputStream());
Out.println(new String(new StringBuffer(r)));
Out.flush();
}
else if(!Identify.CheckQQPassword())
{
String r="P"; //密码错误
Out=new PrintWriter(clientSocket.getOutputStream());
Out.println(new String(new StringBuffer(r)));
Out.flush();
}
else
{
String r="K"; //验证成功
服务器界面.clientOnlineList.AddNewMember(QQNumber,IsHide,clientSocket);
try {
QueryInformation PersonalInformation=new QueryInformation(QQNumber);
NickName=PersonalInformation.GetNickName();
r=r+NickName+"|";
r=r+PersonalInformation.GetTrueName()+"|";
r=r+PersonalInformation.GetSex()+"|";
r=r+PersonalInformation.GetAge()+"|";
r=r+PersonalInformation.GetLeavingInformation()+"|";
Icon=PersonalInformation.GetIcon();
r=r+Icon+"|";
r=r+PersonalInformation.GetSign()+"|";
String s=PersonalInformation.GetFriendList();
r=r+s+"|";
r=r+PersonalInformation.GetOnlineTime()+"|";
r=r+PersonalInformation.GetRequestList()+"|";
r=r+PersonalInformation.GetResponseList()+"|";
r=r+PersonalInformation.GetGroupList()+"|";
r=r+PersonalInformation.GetMyGroup()+"|";
r=r+PersonalInformation.GetMessage()+"|";
r=r+PersonalInformation.GetGroupLeavingMessage()+"|";
String Online=TellYouWhoIsOnLine(s);
r=r+Online+"|";
System.out.println(r);
Out=new PrintWriter(clientSocket.getOutputStream());
Out.println(new String(new StringBuffer(r)));
Out.flush();
if(!IsHide){
UpdateOnlineListOn(s);//告诉我所有的好友我上线了
}
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
/*int i=0;
for(i=0;i<服务器界面.clientOnlineList.GetLength();i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -