public LoginCompletedEventArgs(PDAuthentificationResp resp, Exception e, bool pcanceled, object state) : base(e,pcanceled,state) { this.Canceled = pcanceled; Reponse = resp; }
public static PD createPd(byte[] data) { int pdType = 0x000000FF & (int)data[0]; E_PD_TYPE pdTypeEnum = (E_PD_TYPE)pdType; PD pd = null; MemoryStream ms = new MemoryStream(data); BinaryReader br = new BinaryReader(ms); switch (pdTypeEnum) { case E_PD_TYPE.AUTHENTIFICATION_RESP: pd = new PDAuthentificationResp(); pd.unmarshal(br); break; case E_PD_TYPE.AUTHENTIFICATION: pd = new PDAuthentification(); pd.unmarshal(br); break; case E_PD_TYPE.DELETEPLAYER: pd = new PDDeletePlayer(); pd.unmarshal(br); break; case E_PD_TYPE.DELETETABLE: pd = new PDDeleteTable(); pd.unmarshal(br); break; case E_PD_TYPE.INSERTPLAYER: pd = new PDInsertPlayer(); pd.unmarshal(br); break; case E_PD_TYPE.INSERTTABLE: pd = new PDInsertTable(); pd.unmarshal(br); break; case E_PD_TYPE.UPDATEPPLAYERSTATE: pd = new PDUpdatePlayerState(); pd.unmarshal(br); break; case E_PD_TYPE.UPDATETABLESTATE: pd = new PDUpdateTableState(); pd.unmarshal(br); break; case E_PD_TYPE.UPDATECELL: pd = new PDUpdateCell(); pd.unmarshal(br); break; case E_PD_TYPE.UPDATECELLREQUEST: pd = new PDUpdateCellRequest(); pd.unmarshal(br); break; case E_PD_TYPE.UPDATEPPLAYERTABLESTATE: pd = new PDUpdatePlayerTableState(); pd.unmarshal(br); break; case E_PD_TYPE.PUBLICCHAT: pd = new PDPublicChat(); pd.unmarshal(br); break; case E_PD_TYPE.PRIVATECHAT: pd = new PDPrivateChat(); pd.unmarshal(br); break; case E_PD_TYPE.NEWTABLE: pd = new PDNewTable(); pd.unmarshal(br); break; case E_PD_TYPE.JOINTABLE: pd = new PDJoinTable(); pd.unmarshal(br); break; case E_PD_TYPE.JOINTABLERESPONSE: pd = new PDJoinTableResponse(); pd.unmarshal(br); break; case E_PD_TYPE.EXITTABLE: pd = new PDExitTable(); pd.unmarshal(br); break; case E_PD_TYPE.STARTTABLEGAME: pd = new PDStartTableGame(); pd.unmarshal(br); break; case E_PD_TYPE.GAMEFINISH: pd = new PDGameFinish(); pd.unmarshal(br); break; case E_PD_TYPE.LISTOFPLAYERREQUEST: pd = new PDListOfPlayerRequest(); pd.unmarshal(br); break; case E_PD_TYPE.LISTOFTABLEREQUEST: pd = new PDListOfPlayerRequest(); pd.unmarshal(br); break; case E_PD_TYPE.ERROR: pd = new PDError(); pd.unmarshal(br); break; } br.Close(); return pd; }
private void LoginCompletionMethod(PDAuthentificationResp resp, bool canceled, Exception e, AsyncOperation asyncOp) { LoginCompletedEventArgs args = new LoginCompletedEventArgs(resp,e, canceled, asyncOp.UserSuppliedState); args.Client = instance; asyncOp.PostOperationCompleted(onCompletedLoginDelegate, args); }
private void LoginWorker(string plogin, string ppass, AsyncOperation asyncOp) { if (m_clientSocket != null) { try { Stop(); } catch { } } Canceled = false; m_clientSocket = new TcpClient(); Exception ex = null; byte[] buffer = new byte[PD.MAX_PACKET_SIZE]; int size; bool response = false; PD receivedPD=new PDAuthentificationResp(); ((PDAuthentificationResp)receivedPD).Succeded = false; try { IniFile ini = new IniFile(Application.StartupPath + "\\opensudoku.ini"); m_host = ini.IniReadValue("GENERAL", "Host", "127.0.0.1"); m_port = int.Parse(ini.IniReadValue("GENERAL", "Port", "31200")); m_clientSocket.Connect(System.Net.IPAddress.Parse(Host), Port); NetworkStream stream = m_clientSocket.GetStream(); BinaryReader br = new BinaryReader(stream); PDAuthentification loginPD = new PDAuthentification(plogin, ppass); byte[] data = loginPD.getBytesData(); stream.Write(data, 0, data.Length); while (!Canceled) { size = stream.Read(buffer, 0, buffer.Length); if (size > PD.MIN_PACKET_SIZE) { receivedPD = PDFactory.createPd(buffer); if (receivedPD.PDType == E_PD_TYPE.AUTHENTIFICATION_RESP) { response = ((PDAuthentificationResp)receivedPD).Succeded; } break; } } ex = null; //stream.Close(); } catch (SocketException e) { ex = e; } catch (Exception e) { ex = e; } finally { LoginCompletionMethod((PDAuthentificationResp)receivedPD, false, ex, asyncOp); } }
private void PlayerLoginReceived(PDAuthentification pdReceived) { bool succeeded; Player player = null; if (Player.isValidPlayer(out player, pdReceived.Login, pdReceived.Pass)) { succeeded = true; m_player = player; m_authentified = succeeded; PDAuthentificationResp pd = new PDAuthentificationResp(player.PlayerID, player.Login, player.Email, player.Score); m_socketClient.sendPacket(pd); if (PlayerConectedEvent != null) { PlayerConectedEvent(this, new PlayerEventArgs(player)); } #if DEBUG Console.WriteLine("PlayerLoginReceived " + player); #endif } else { succeeded = false; m_authentified = succeeded; PDAuthentificationResp pd = new PDAuthentificationResp(succeeded); m_socketClient.sendPacket(pd); #if DEBUG Console.WriteLine("PlayerLoginReceived invalid user : "******"@" + pdReceived.Pass); #endif } }