PutUInt() public method

Put the given uint at the current offset.
public PutUInt ( uint s ) : void
s uint uint to insert
return void
コード例 #1
0
ファイル: NetIO.cs プロジェクト: zNext666/SagaECO
        /// <summary>
        /// Sends a packet, which is not yet encrypted, to the client.
        /// </summary>
        /// <param name="p">The packet containing all info.</param>
        public void SendPacket(Packet p, bool nolength, bool noWarper)
        {
            if (!noWarper)
            {
                byte[] buf = new byte[p.data.Length + firstLevelLenth];
                Array.Copy(p.data, 0, buf, firstLevelLenth, p.data.Length);
                p.data = buf;
                if (firstLevelLenth == 4)
                {
                    p.SetLength();
                }
                else
                {
                    p.PutUShort((ushort)(p.data.Length - 2), 0);
                }
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
                p.SetLength();
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
            }
            if (!nolength)
            {
                int mod = 16 - ((p.data.Length - 8) % 16);
                if (mod != 0)
                {
                    byte[] buf = new byte[p.data.Length + mod];
                    Array.Copy(p.data, 0, buf, 0, p.data.Length);
                    p.data = buf;
                }
                p.PutUInt((uint)(p.data.Length - 8), 0);
            }

            try
            {
                byte[] data;
                data = Crypt.Encrypt(p.data, 8);
                sock.BeginSend(data, 0, data.Length, SocketFlags.None, null, null);
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex);
                this.Disconnect();
            }
        }
コード例 #2
0
ファイル: Mob.cs プロジェクト: Willyham/SagaRO2
 public override void OnDie()
 {
     base.OnDie();
     if( delay != -1 )
         respawnTask.Activate();
     corpsetask.Activate();
     ai.Pause();
     if( this.map.GetActor( this.timeSignature.actorID ) != null )
     {
         ActorPC pc = (ActorPC)this.map.GetActor( this.timeSignature.actorID );
         ActorEventHandlers.PC_EventHandler eh = (SagaMap.ActorEventHandlers.PC_EventHandler)pc.e;
         Packet p = new Packet();//don't know its name,maybe for some animation.
         p.data = new byte[9];
         p.ID = 0x060E;
         p.PutUInt( this.Actor.id, 4 );
         p.PutByte( 4, 8 );
         eh.C.netIO.SendPacket(p, eh.C.SessionID);
         SagaDB.Quest.Quest quest = Quest.QuestsManager.GetActiveQuest( pc );
         if( quest != null )//Add a temporary loot for a specificial quest
         {
             if( Quest.QuestsManager.MobQuestItem.ContainsKey( this.Actor.npcType ) )
             {
                 foreach( Quest.QuestsManager.LootInfo i in Quest.QuestsManager.MobQuestItem[this.Actor.npcType] )
                 {
                     if( i.QID == quest.ID )
                     {
                         if( quest.Steps.ContainsKey( i.SID ) )
                         {
                             if( quest.Steps[i.SID].Status == 1 )
                             {
                                 if( this.Actor.NPCinv == null ) Actor.NPCinv = new List<Item>();
                                 int j = Global.Random.Next( 0, 9999 );
                                 if( j < i.rate )
                                     this.Actor.NPCinv.Add( new Item( i.itemID ) );
                                 return;
                             }
                         }
                     }
                 }
             }
         }
         /*if (eh.C.QuestMobItem != null)
         {
             if (eh.C.QuestMobItem.ContainsKey(this.Actor.npcType))
             {
                 if (this.Actor.NPCinv == null) Actor.NPCinv = new List<Item>();
                 this.Actor.NPCinv.Add(ItemFactory.GetItem((int)eh.C.QuestMobItem[this.Actor.npcType]));
             }
         }*/
     }
 }
コード例 #3
0
ファイル: NetIO.cs プロジェクト: yasuhiro91/SagaECO
 private void ReceiveKeyExchange(IAsyncResult ar)
 {
     try
     {
         if (this.isDisconnected)
         {
             return;
         }
         if (!sock.Connected)
         {
             ClientManager.EnterCriticalArea();
             this.Disconnect();
             ClientManager.LeaveCriticalArea();
             return;
         }
         try { stream.EndRead(ar); }
         catch (Exception)
         {
             ClientManager.EnterCriticalArea();
             this.Disconnect();
             ClientManager.LeaveCriticalArea();
             return;
         }
         byte[] raw = (byte[])ar.AsyncState;
         if (raw.Length == 8)
         {
             Packet p1 = new Packet(529);
             p1.PutUInt(1, 4);
             p1.PutByte(0x32, 8);
             p1.PutUInt(0x100, 9);
             Crypt.MakePrivateKey();
             string bufstring = Conversions.bytes2HexString(Encryption.Module.getBytes());
             p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring.ToLower()), 13);
             p1.PutUInt(0x100, 269);
             bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes());
             p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 273);
             SendPacket(p1, true, true);
             try
             {
                 byte[] data = new byte[260];
                 stream.BeginRead(data, 0, 260, this.callbackKeyExchange, data);
             }
             catch (Exception)
             {
                 ClientManager.EnterCriticalArea();
                 this.Disconnect();
                 ClientManager.LeaveCriticalArea();
                 return;
             }
         }
         else if (raw.Length == 260)
         {
             Packet p1 = new Packet();
             p1.data = raw;
             byte[] keyBuf = p1.GetBytes(256, 4);
             Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf));
             StartPacketParsing();
         }
         else if (raw.Length == 529)
         {
             Packet p1 = new Packet();
             p1.data = raw;
             byte[] keyBuf = p1.GetBytes(256, 273);
             Crypt.MakePrivateKey();
             Packet p2 = new Packet(260);
             p2.PutUInt(0x100, 0);
             string bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes());
             p2.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 4);
             SendPacket(p2, true, true);
             Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf));
             StartPacketParsing();
         }
     }
     catch (Exception ex)
     {
         Logger.ShowError(ex);
     }
 }
コード例 #4
0
ファイル: NetIO.cs プロジェクト: zNext666/SagaECO
 private void ReceiveKeyExchange(IAsyncResult ar)
 {
     try
     {
         if (this.isDisconnected)
         {
             return;
         }
         if (!sock.Connected)
         {
             ClientManager.EnterCriticalArea();
             this.Disconnect();
             ClientManager.LeaveCriticalArea();
             return;
         }
         try { stream.EndRead(ar); }
         catch (Exception)
         {
             ClientManager.EnterCriticalArea();
             this.Disconnect();
             ClientManager.LeaveCriticalArea();
             return;
         }
         byte[] raw = (byte[])ar.AsyncState;
         if (raw.Length == 8)
         {
             Packet p1 = new Packet(529);
             p1.PutUInt(1, 4);
             p1.PutByte(0x32, 8);
             p1.PutUInt(0x100, 9);
             Crypt.MakePrivateKey();
             string bufstring = Conversions.bytes2HexString(Encryption.Module.getBytes());
             p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring.ToLower()), 13);
             p1.PutUInt(0x100, 269);
             bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes());
             p1.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 273);
             SendPacket(p1, true, true);
             try
             {
                 byte[] data = new byte[260];
                 stream.BeginRead(data, 0, 260, this.callbackKeyExchange, data);
             }
             catch (Exception)
             {
                 ClientManager.EnterCriticalArea();
                 this.Disconnect();
                 ClientManager.LeaveCriticalArea();
                 return;
             }
         }
         else if (raw.Length == 260)
         {
             Packet p1 = new Packet();
             p1.data = raw;
             byte[] keyBuf = p1.GetBytes(256, 4);
             Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf));
             StartPacketParsing();
         }
         else if (raw.Length == 529)
         {
             Packet p1 = new Packet();
             p1.data = raw;
             byte[] keyBuf = p1.GetBytes(256, 273);
             Crypt.MakePrivateKey();
             Packet p2 = new Packet(260);
             p2.PutUInt(0x100, 0);
             string bufstring = Conversions.bytes2HexString(Crypt.GetKeyExchangeBytes());
             p2.PutBytes(System.Text.Encoding.ASCII.GetBytes(bufstring), 4);
             SendPacket(p2, true, true);
             Crypt.MakeAESKey(System.Text.Encoding.ASCII.GetString(keyBuf));
             StartPacketParsing();
         }
     }
     catch (Exception ex)
     {
         Logger.ShowError(ex);
     }
 }
コード例 #5
0
ファイル: NetIO.cs プロジェクト: yasuhiro91/SagaECO
        /// <summary>
        /// Sends a packet, which is not yet encrypted, to the client.
        /// </summary>
        /// <param name="p">The packet containing all info.</param>
        public void SendPacket(Packet p, bool nolength, bool noWarper)
        {
            if (!noWarper)
            {
                byte[] buf = new byte[p.data.Length + firstLevelLenth];
                Array.Copy(p.data, 0, buf, firstLevelLenth, p.data.Length);
                p.data = buf;
                if (firstLevelLenth == 4)
                    p.SetLength();
                else
                    p.PutUShort((ushort)(p.data.Length - 2), 0);
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
                p.SetLength();
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
            }
            if (!nolength)
            {
                int mod = 16-((p.data.Length - 8) % 16);
                if (mod != 0)
                {
                    byte[] buf = new byte[p.data.Length + mod];
                    Array.Copy(p.data, 0, buf, 0, p.data.Length);
                    p.data = buf;
                }
                p.PutUInt((uint)(p.data.Length - 8), 0);
            }

            try
            {
                byte[] data;
                data = Crypt.Encrypt(p.data, 8);
                sock.BeginSend(data, 0, data.Length, SocketFlags.None, null, null);
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex);
                this.Disconnect();
            }
        }