Ссылка на объект не указывает на экземпляр объекта - C# (186518)
Формулировка задачи:
Ссылка на объект не указывает на экземпляр объекта
Вот в этих файлах
Строка 488
http://pastebin.com/p8MJjEZ8
Строка 21
Строка 22
Строка 78
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SmartEngine.Network;
- using SagaBNS.Common.Packets;
- using SagaBNS.CharacterServer.Network.Client;
- namespace SagaBNS.CharacterServer.Packets.Client
- {
- public class CM_ACTOR_INFO_REQUEST : SagaBNS.Common.Packets.CharacterServer.CM_ACTOR_INFO_REQUEST
- {
- public override Packet<CharacterPacketOpcode> New()
- {
- return new CM_ACTOR_INFO_REQUEST();
- }
- public override void OnProcess(Session<CharacterPacketOpcode> client)
- {
- ((CharacterSession)client).OnActorInfoRequest(this);
- }
- }
- }
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SmartEngine.Core;
- using SmartEngine.Network;
- using SagaBNS.Common.Packets;
- using SagaBNS.Common.Packets.CharacterServer;
- using SagaBNS.Common.Actors;
- using SagaBNS.CharacterServer.Database;
- using SagaBNS.CharacterServer.Cache;
- namespace SagaBNS.CharacterServer.Network.Client
- {
- public partial class CharacterSession : Session<CharacterPacketOpcode>
- {
- public void OnActorInfoRequest(Packets.Client.CM_ACTOR_INFO_REQUEST p)
- {
- SM_ACTOR_INFO r= new SM_ACTOR_INFO();
- r.SessionID = p.SessionID;
- r.Character = CharacterCache.Instance[p.CharID];
- this.Network.SendPacket(r);
- }
- public void OnCharListRequest(Packets.Client.CM_CHAR_LIST_REQUEST p)
- {
- Logger.ShowInfo(string.Format(this + ":Player is requesting char list for account ID:{0}", p.AccountID));
- SM_CHAR_LIST p1 = new SM_CHAR_LIST();
- p1.SessionID = p.SessionID;
- List<uint> ids = CharacterDB.Instance.GetCharIDs(p.AccountID);
- foreach(uint i in CharacterCache.Instance.GetCharIDsForAccount(p.AccountID))
- {
- if(!ids.Contains(i))
- ids.Add(i);
- }
- List<ActorPC> res = new List<ActorPC>();
- foreach (uint i in ids)
- {
- ActorPC pc = CharacterCache.Instance[i];
- if (pc != null)
- res.Add(pc);
- }
- p1.Characters = res;
- Logger.ShowInfo(string.Format(this + ":Got {0} Characters", res.Count));
- this.Network.SendPacket(p1);
- }
- public void OnCharCreate(Packets.Client.CM_CHAR_CREATE p)
- {
- SM_CHAR_CREATE_RESULT p1 = new SM_CHAR_CREATE_RESULT();
- p1.SessionID = p.SessionID;
- ActorPC chara = p.Character;
- if (CharacterDB.Instance.CheckExists(chara.Name, chara.WorldID))
- {
- p1.Result = SM_CHAR_CREATE_RESULT.Results.ERROR;
- p1.CharID = p.Character.CharID;
- }
- else
- {
- p1.Result = SM_CHAR_CREATE_RESULT.Results.OK;
- p1.CharID = CharacterCache.Instance.Create(p.Character);
- }
- this.Network.SendPacket(p1);
- }
- public void OnCharSave(Packets.Client.CM_CHAR_SAVE p)
- {
- ActorPC pc = p.Character;
- BackupData(pc,CharacterCache.Instance[pc.CharID]);
- CharacterCache.Instance.Save(pc.CharID, pc);
- }
- public void OnCharDelete(Packets.Client.CM_CHAR_DELETE p)
- {
- Logger.ShowInfo(string.Format("Requested deletion of character ID {0}", p.CharID));
- CharacterCache.Instance.Delete(p.CharID);
- SM_CHAR_DELETE_RESULT p1 = new SM_CHAR_DELETE_RESULT();
- p1.SessionID = p.SessionID;
- p1.Result = SM_CHAR_DELETE_RESULT.Results.OK;
- this.Network.SendPacket(p1);
- }
- void BackupData(ActorPC newPC,ActorPC oldPC)
- {
- if (oldPC == null)
- return;
- newPC.Quests = oldPC.Quests;
- newPC.QuestsCompleted = oldPC.QuestsCompleted;
- newPC.Skills = oldPC.Skills;
- newPC.Locations = oldPC.Locations;
- }
- }
- }
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SmartEngine.Network;
- using SagaBNS.Common.Actors;
- using SagaBNS.Common.Network;
- namespace SagaBNS.Common.Packets.CharacterServer
- {
- public class SM_ACTOR_INFO : Packet<CharacterPacketOpcode>
- {
- internal class SM_ACTOR_INFO_INTERNAL<T> : SM_ACTOR_INFO
- {
- public override Packet<CharacterPacketOpcode> New()
- {
- return new SM_ACTOR_INFO_INTERNAL<T>();
- }
- public override void OnProcess(Session<CharacterPacketOpcode> client)
- {
- ((CharacterSession<T>)client).OnActorInfo(this);
- }
- }
- public SM_ACTOR_INFO()
- {
- this.ID = CharacterPacketOpcode.SM_ACTOR_INFO;
- }
- public long SessionID
- {
- get
- {
- return GetLong(2);
- }
- set
- {
- PutLong(value, 2);
- }
- }
- public ActorPC Character
- {
- get
- {
- ActorPC pc = new ActorPC();
- pc.CharID = GetUInt();
- pc.AccountID = GetUInt();
- pc.SlotID = GetByte();
- pc.WorldID = GetByte();
- pc.Name = GetString();
- pc.Level = GetByte();
- pc.Exp = GetUInt();
- pc.Race = (Race)GetByte();
- pc.Gender = (Gender)GetByte();
- pc.Job = (Job)GetByte();
- pc.Appearence1 = GetBytes(GetByte());
- pc.Appearence2 = GetBytes(GetByte());
- pc.UISettings = GetString();
- pc.PartyID = GetULong();
- pc.Offline = GetByte() == 1;
- pc.Exp = GetUInt();
- pc.HP = GetInt();
- pc.MP = GetUShort();
- pc.MaxHP = GetInt();
- pc.MaxMP = GetUShort();
- pc.Gold = GetInt();
- pc.MapID = GetUInt();
- pc.X = GetShort();
- pc.Y = GetShort();
- pc.Z = GetShort();
- pc.Dir = GetUShort();
- pc.InventorySize = GetByte();
- return pc;
- }
- set
- {
- PutUInt(value.CharID);
- PutUInt(value.AccountID);
- PutByte(value.SlotID);
- PutByte(value.WorldID);
- PutString(value.Name);
- PutByte(value.Level);
- PutUInt(value.Exp);
- PutByte((byte)value.Race);
- PutByte((byte)value.Gender);
- PutByte((byte)value.Job);
- PutByte((byte)value.Appearence1.Length);
- PutBytes(value.Appearence1);
- PutByte((byte)value.Appearence2.Length);
- PutBytes(value.Appearence2);
- PutString(value.UISettings);
- PutULong(value.PartyID);
- PutByte(value.Offline ? (byte)1 : (byte)0);
- PutUInt(value.Exp);
- PutInt(value.HP);
- PutUShort((ushort)value.MP);
- PutInt(value.MaxHP);
- PutUShort(value.MaxMP);
- PutInt(value.Gold);
- PutUInt(value.MapID);
- PutShort((short)value.X);
- PutShort((short)value.Y);
- PutShort((short)value.Z);
- PutUShort(value.Dir);
- PutByte(value.InventorySize);
- }
- }
- }
- }
Решение задачи: «Ссылка на объект не указывает на экземпляр объекта»
textual
Листинг программы
- OnActorInfoRequest
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д