ServerProtocol.cpp
上传用户:bsw_2008
上传日期:2013-07-09
资源大小:2446k
文件大小:3k
- // ServerProtocol.cpp: implementation of the CServerProtocol class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "CServerFrame.h"
- #include "ServerProtocol.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- char CH=char(20);
- CServerProtocol::CServerProtocol()
- {
- }
- CServerProtocol::~CServerProtocol()
- {
- }
- char CServerProtocol::Analasys(CString str)
- {
- message=str;
- char k=' ',ch;int i=0,len=str.GetLength();
- ch=str.GetAt(i);
- if(ch!=CH)
- return k;
- k=str.GetAt(++i);
- switch(k)
- {
- case 'A':desk=0;
- ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- desk=desk*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- ch=str.GetAt(++i);chat.Empty();
- while(ch!=CH)
- {
- chat+=ch;ch=str.GetAt(++i);
- }
- break;
- case 'B':
- case 'P':
- case 'Q':
- desk=0;
- ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- desk=desk*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- ch=str.GetAt(++i);
- direct=(int)(ch-'0');
- break;
- case 'C':
- desk=0;
- ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- desk=desk*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- direct=(int)(str.GetAt(++i)-'0');i++;
- toBoard(str,i);
- break;
- case 'E':
- desk=0;
- ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- desk=desk*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- direct=(int)(str.GetAt(++i)-'0');i++;
- toMove(str,i);
- break;
- case 'L':
- ch=str.GetAt(++i);code.Empty();
- while(ch!=' '&&ch!=CH)
- {
- code+=ch;
- ch=str.GetAt(++i);
- }
- if(ch=str.GetAt(++i)=='1')
- sex="男";
- else
- sex="女";
- break;
- case 'N':
- ch=str.GetAt(++i);name.Empty();
- while(ch!=' '&&ch!=CH)
- {
- name+=ch;
- ch=str.GetAt(++i);
- }
- ch=str.GetAt(++i);code.Empty();
- while(ch!=' '&&ch!=CH)
- {
- code+=ch;
- ch=str.GetAt(++i);
- }
- break;
- }
- return k;
- }
- void CServerProtocol::toBoard(CString str,int i)
- {
- int n,j,k;
- char ch;
- for(j=11;j<17;j++)
- for(k=6;k<11;k++)
- {
- ch=str.GetAt(++i);
- n=0;
- while(ch!=' '&&ch!=CH)
- {
- n=n*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- board[j][k]=n;
- }
- }
- void CServerProtocol::toMove(CString str, int i)
- {
- int n=0;char ch;
- ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- n=n*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- from.x=n;
- n=0;ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- n=n*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- from.y=n;
- n=0;ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- n=n*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- to.x=n;
- n=0;ch=str.GetAt(++i);
- while(ch!=' '&&ch!=CH)
- {
- n=n*10+(int)(ch-'0');
- ch=str.GetAt(++i);
- }
- to.y=n;
- }
- CString CServerProtocol::toString(char k, int DESK, int DIRECT, int fromX, int fromY, int toX, int toY)
- {
- CString str=CH;
- switch(k)
- {
- case 'F':
- case 'G':
- case 'H':
- str+=k;
- str.Format("%d %d %d %d %d",DESK,fromX,fromY,toX,toY);
- str+=CH;
- break;
- case 'I':
- case 'J':
- case 'K':
- str+=k;
- str.Format("%d %d",DESK,DIRECT);
- str+=CH;
- break;
- default:
- break;
- }
- if(str.GetLength()==1)
- str=' ';
- return str;
- }