public CPlayer(CClient sClient) { Client = sClient; Session = new CSession(); Session.ClientID = 0; Session.CtlCode = 0; Session.isInGame = false; Session.isLoggedIn = false; Session.password = ""; Session.username = ""; CharInfo = new CInfo(); CharInfo.CharID = 0; CharInfo.BodyID = 0; CharInfo.CharName = ""; CharInfo.Class = 0; CharInfo.cLevel = 0; CharInfo.cExp = 0; CharInfo.cGold = 0; CharInfo.MasterPts = 0; CharInfo.sGold = 0; CharInfo.SkillPts = 0; CharInfo.StatPts = 0; Inventory = new CItem[78]; for (int i = 0; i < 78; i++) { ClearItem(Inventory[i]); } }
public void PacketHandler(CClient thisclient, CPacket thispacket) { if (thispacket.dataBuffer[0] + thispacket.dataBuffer[1] == 0x74) { Packets.pak_AccountLogin(thispacket.dataBuffer, thisclient.Player); } else if (thispacket.dataBuffer[4] + thispacket.dataBuffer[5] == 0x74) { Packets.pak_AccountLogin(thispacket.dataBuffer, thisclient.Player); } else { if (thispacket.dataBuffer[0] + thispacket.dataBuffer[1] != 0x0104) { byte[] psize = new byte[2]; int lastbyte = 0; int decsize = 0; while (thisclient.PacketSize != lastbyte) { Buffer.BlockCopy(thispacket.dataBuffer, lastbyte, psize, 0, 2); int paksize = BitConverter.ToInt16(psize, 0); byte[] buff = new byte[paksize]; byte[] src = new byte[paksize]; Buffer.BlockCopy(thispacket.dataBuffer, lastbyte, src, 0, paksize); decsize = thisclient.encdec.Decrypt(buff, src, paksize); lastbyte = lastbyte + paksize; Packets.PacketOpcodeControl(buff, thisclient.Player, paksize); } } } }
public bool VisionList(CPlayer thisclient) { foreach (object client in m_ClientList) { CClient otherclient = (CClient)client; int distance = Distance(thisclient.Position.pCurrent, otherclient.Player.Position.pCurrent); if (CVisionFunc.isVisible(thisclient, otherclient.Player)) { if (distance < 50) { thisclient.vPlayers.Add(otherclient.Player); } else { thisclient.vPlayers.Remove(otherclient.Player); Packets.pak_DeleteCharSpawn(thisclient, otherclient.Player); } } else { if (distance < 20) { thisclient.vPlayers.Add(otherclient.Player); Packets.pak_SpawnChar(thisclient, otherclient.Player); } } } foreach (object npc in NpcList) { CNpc thisnpc = (CNpc)npc; int distance = Distance(thisclient.Position.pCurrent, thisnpc.Position.pCurrent); if (CVisionFunc.isNpcVisible(thisclient, thisnpc)) { if (distance < 50) { thisclient.vNpcs.Add(thisnpc); } else { thisclient.vNpcs.Remove(thisnpc); Packets.pak_DeleteNpcSpawn(thisclient, thisnpc); } } else { if (distance < 20) { thisclient.vNpcs.Add(thisnpc); Packets.pak_SpawnNpc(thisclient, thisnpc); } } } return(true); }
public void VisionProcess() { while (true) { foreach (object client in Server.m_ClientList) { CClient thisclient = (CClient)client; Server.VisionList(thisclient.Player); } Thread.Sleep(200); } }
public void MapProcess() { while (true) { foreach (object client in Server.m_ClientList) { CClient thisclient = (CClient)client; //thisclient.Player.PlayerMovement(); } Thread.Sleep(10); } }
void CloseSockets() { if (m_Socket != null) { m_Socket.Close(); } for (int i = 0; i < m_ClientList.Count; i++) { CClient thisclient = (CClient)m_ClientList[i]; if (thisclient.sock != null) { thisclient.sock.Close(); thisclient.sock = null; } } }
public void WaitForData(CClient client) { try { if (pfnWorkerCallBack == null) { pfnWorkerCallBack = new AsyncCallback(OnDataReceived); } CPacket thispacket = new CPacket(client); client.sock.BeginReceive(thispacket.dataBuffer, 0, thispacket.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, thispacket); } catch (SocketException se) { Core.CLog(se.Message); } }
public void OnDataReceived(IAsyncResult asyn) { CClient thisclient = null; CPacket thispacket = (CPacket)asyn.AsyncState; try { m_PacketSize = thispacket.m_thisClient.sock.EndReceive(asyn); thisclient = thispacket.m_thisClient; thisclient.PacketSize = m_PacketSize; // Packets if (m_PacketSize > 0) { PacketHandler(thisclient, thispacket); } else { thisclient.sock.Disconnect(false); } if (thispacket.m_thisClient.sock.Connected) { WaitForData(thisclient); } } catch (SocketException se) { if (se.ErrorCode == 10054) { // Client Disconnect //Packets.pak_PlayerDisconnect(thispacket.dataBuffer, thisclient.Player); Core.CLog(String.Format("Client Disconnected {0}", thispacket.m_thisClient.sock.RemoteEndPoint.ToString())); } else { Core.CLog(se.Message); } } }
public void OnClientConnect(IAsyncResult asyn) { CClient thisclient = new CClient(this); CPlayer player; allDone.Set(); try { thisclient.sock = m_Socket.EndAccept(asyn); m_ClientCount++; player = new CPlayer(thisclient); thisclient.Player = player; m_ClientList.Add(thisclient); WaitForData(thisclient); Core.CLog(String.Format("Client Connected {0}", thisclient.sock.RemoteEndPoint.ToString())); m_Socket.BeginAccept(new AsyncCallback(OnClientConnect), null); } catch (SocketException se) { Core.CLog(se.Message); } }
public CPacket(CClient thisclient) { dataBuffer = new byte[65535]; m_thisClient = thisclient; }