public static bool Read( NetState State, string Name, string Password, out Account Acc ) { Acc = new Account(); Acc.Netstate = State; ResultTable table = Core.Database.Query( "SELECT * FROM accounts WHERE name = '{0}' AND password = '******' LIMIT 0,1", Name.MysqlEscape(), Password.MysqlEscape() ); table.TableName = "Account Table"; if( table.Rows.Count == 0 ) return false; ResultRow row = table[ 0 ]; Acc.Serial = new Serial( row[ "account_id" ].GetInt(), ESerialType.Account ); Acc.Name = row[ "name" ].GetString(); Acc.Password = row[ "password" ].GetString(); Acc.LastIP = row[ "last_ip" ].GetString(); Acc.LastLogin = row[ "last_login" ].GetInt(); Acc.Email = row[ "email" ].GetString(); Acc.UpdateLastLogin(); table = Core.Database.Query( "SELECT * FROM chars WHERE account_id = {0}", Acc.Serial.Value ); table.TableName = "Char Table"; if( table.Rows.Count == 0 ) return true; Character c; while( ( row = table.GetNext() ) != null ) { c = new Character( Acc, row[ "char_id" ].GetInt(), row[ "name" ].GetString() ); Acc.Chars.Add( c.Serial, c ); } return true; }
public void OnUseScript( NetState Player, BaseItem Item ) { for( int i = 0; i < mHandler.Count; i++ ) { if( mHandler[ i ] == null ) continue; Item.ScriptArgs = mArguments[ i ]; mHandler[ i ]( Player, Item ); } }
private void CheckListener() { Socket[] accepted = mListener.Slice(); for( int i = 0; i < accepted.Length; ++i ) { NetState ns = new NetState( accepted[ i ], this ); ns.Start(); if( ns.Running ) { CConsole.StatusLine( "{0}: Connected. [{1} Online]", ns, NetState.Instances.Count ); ns.Send( new Packet0xA101( ns ) ); } } }
public void OnReceive( NetState ns ) { lock( this ) mQueue.Enqueue( ns ); Core.Set(); }
public bool HandleReceive( NetState ns ) { ByteQueue buffer = ns.Buffer; if( buffer == null || buffer.Length <= 0 ) return true; CConsole.DebugLine( "{0}: Incoming Data - {1} Bytes", ns, buffer.Length ); /* * Packet Analyse/verify && Parsing */ lock( buffer ) { int length = buffer.Length; // debug Data while( length > 0 && ns.Running ) { short packetID = buffer.GetPacketID(); // debug log using( TextWriter writer = File.CreateText( AppDomain.CurrentDomain.BaseDirectory + @"\packet_" + DateTime.Now.UnixTimestamp() + ".log" ) ) { using( MemoryStream ms = new MemoryStream( buffer.ByteBuffer ) ) Tools.FormatBuffer( writer, ms, (int)ms.Length ); } CConsole.DebugLine( "{0}: packetID {1}, {2} bytes", ns, packetID, length ); PacketHandler handler = PacketHandlers.GetHandler( packetID ); if( handler == null ) { byte[] data = new byte[ length ]; length = buffer.Dequeue( data, 0, length ); CConsole.ErrorLine( "{0}: no Handler found! Data dispose", ns ); break; } CConsole.StatusLine( "{0}: Handler found ({1} bytes)! Trigger Callback...", ns, handler.Length ); byte[] packetBuffer; if( mBufferSize >= handler.Length ) packetBuffer = mBuffers.AcquireBuffer(); else packetBuffer = new byte[ handler.Length ]; buffer.Dequeue( packetBuffer, 0, handler.Length ); PacketReader r = new PacketReader( packetBuffer, handler.Length, 0 ); handler.OnReceive( ns, r ); length = buffer.Length; if( mBufferSize >= handler.Length ) mBuffers.ReleaseBuffer( packetBuffer ); } // end while()*/ } // end Lock() return true; }
/// <summary> /// Generic Method to add HP /// </summary> /// <param name="Player"></param> /// <param name="Item"></param> public static void AddHP( NetState Player, BaseItem Item ) { if( Item.ScriptArgs == null || Item.ScriptArgs.Length == 0 ) return; //Player.Active.Status.AddHP( (int)Item.ScriptArgs[ 0 ] ); // gets <Value> HP }
/// <summary> /// an Empty/Unused/not yet available Packet Handler /// </summary> /// <param name="state"></param> /// <param name="reader"></param> public static void EmptyHandler( NetState state, PacketReader reader ) { }
public void OnUseScript( NetState Player ) { mScriptList.OnUseScript( Player, this ); }