Ejemplo n.º 1
0
        private void DB_SaveSocials(UserRole role)
        {
            var items = role.SocialManager.SaveSocialList();

            foreach (var i in items)
            {
                CSCommon.Data.SocialData outItem = null;
                foreach (var j in role.Socials)
                {
                    if (j.OtherId == i.OtherId)
                    {
                        outItem = j;
                        break;
                    }
                }
                if (outItem != null)
                {
                    string condition = "OtherId = " + i.OtherId;
                    ServerFrame.DB.DBOperator dbOp = ServerFrame.DB.DBConnect.UpdateData(condition, i, outItem);
                    mDBConnect._ExecuteUpdate(dbOp);
                }
                else
                {
                    string condition = "OtherId = " + i.OtherId;
                    ServerFrame.DB.DBOperator dbOp = ServerFrame.DB.DBConnect.ReplaceData(condition, i, true);
                    mDBConnect._ExecuteInsert(dbOp);
                }
            }
            role.Socials = items;
        }
Ejemplo n.º 2
0
        private void DB_InitSocial(UserRole role)
        {
            string condition = "OwnerId=" + role.RoleData.RoleId;

            ServerFrame.DB.DBOperator dbOp = ServerFrame.DB.DBConnect.SelectData(condition, new CSCommon.Data.SocialData(), "");
            System.Data.DataTable     tab  = mDBConnect._ExecuteSelect(dbOp, "SocialData");
            if (tab != null)
            {
                List <CSCommon.Data.SocialData> items = new List <CSCommon.Data.SocialData>();

                foreach (System.Data.DataRow r in tab.Rows)
                {
                    CSCommon.Data.SocialData itemData = new CSCommon.Data.SocialData();
                    if (false == ServerFrame.DB.DBConnect.FillObject(itemData, r))
                    {
                        continue;
                    }
                    items.Add(itemData);
                }
                role.Socials.Clear();
                role.Socials.AddRange(items);
                role.SocialManager.InitSocialList(role);
                items.Clear();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("角色获取关系数据库执行失败:" + dbOp.SqlCode);
            }
        }
Ejemplo n.º 3
0
        public CSCommon.Data.SocialData AddSocial(ulong otherId, CSCommon.eSocialType type)
        {
            CSCommon.Data.SocialData sd = null;
            if (mSocialDict.ContainsKey(otherId))
            {
                Social s = mSocialDict[otherId];
                if (s.IsSocial(type))
                {
                    return(null);
                }
                else
                {
                    s.SetSocial(type, true);
                    sd = s.SocialData;
                }
            }
            else
            {
                sd         = new CSCommon.Data.SocialData();
                sd.OwnerId = mHostRole.RoleData.RoleId;
                sd.OtherId = otherId;
                Social s = new Social(sd);
                s.SetSocial(type, true);
                mSocialDict[sd.OtherId] = s;
            }

            return(sd);
        }
Ejemplo n.º 4
0
 public CSCommon.Data.SocialRoleInfo CreateSocialRoleInfo(CSCommon.Data.SocialData data, UserRole role)
 {
     CSCommon.Data.SocialRoleInfo info = new CSCommon.Data.SocialRoleInfo();
     info.id         = data.OtherId;
     info.name       = role.RoleData.Name;
     info.profession = role.RoleData.Profession;
     info.camp       = role.RoleData.Camp;
     info.level      = role.RoleData.Level;
     info.socialData = data;
     if (role.PlanesConnect != null)
     {
         info.state = (byte)CSCommon.eOnlineState.Online;
     }
     return(info);
 }
Ejemplo n.º 5
0
        public void RPC_AddSocial(ulong roleId, string otherName, byte type, Iocp.NetConnection connect, RPC.RPCForwardInfo fwd)
        {
            RPC.PackageWriter pkg = new RPC.PackageWriter();
            pkg.SetSinglePkg();
            var role = this.GetRole(roleId);

            if (role == null)
            {
                Log.Log.Social.Print("role is null , {0}", roleId);
                pkg.Write((sbyte)CSCommon.eRet_AddSocial.NoRole);
                pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }
            var other = this.GetRole(otherName);

            if (other == null)
            {
                pkg.Write((sbyte)CSCommon.eRet_AddSocial.NoOther);
                pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }
            if (roleId == other.RoleData.RoleId)
            {
                pkg.Write((sbyte)CSCommon.eRet_AddSocial.RoleIsOther);
                pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }
            if (role.SocialManager.IsSocial(other.RoleData.RoleId, (CSCommon.eSocialType)type))
            {
                pkg.Write((sbyte)CSCommon.eRet_AddSocial.IsSocial);  //已经是这种关系
                pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }
            if (role.SocialManager.IsCoupleType((CSCommon.eSocialType)type))
            {
                if (false == role.SocialManager.IsSocial(other.RoleData.RoleId, CSCommon.eSocialType.Friend))
                {
                    pkg.Write((sbyte)CSCommon.eRet_AddSocial.NotFriend);//不是好友
                    pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                    return;
                }
                //发送邀请
                CSCommon.Data.Message msg = CreateMessage(CSCommon.eMessageFrom.Social, _GetSocialMsgType((CSCommon.eSocialType)type), role.RoleData.Name, other.RoleData.RoleId);
                msg.ShowInfo = string.Format("玩家{0}请求与你成为{1}关系", role.RoleData.Name, _GetStrSocial((CSCommon.eSocialType)type));
                SendMessageToOther(other, msg);
                pkg.Write((sbyte)CSCommon.eRet_AddSocial.AskSucceed);
            }
            else
            {
                CSCommon.Data.SocialData sd = role.SocialManager.AddSocial(other.RoleData.RoleId, (CSCommon.eSocialType)type);
                if (sd == null)
                {
                    pkg.Write((sbyte)CSCommon.eRet_AddSocial.IsSocial);   //已经是这种关系
                    pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                    return;
                }
                var info = CreateSocialRoleInfo(sd, other);
                pkg.Write((sbyte)CSCommon.eRet_AddSocial.AddSucceed);
                pkg.Write(info);
                pkg.Write(sd);

                if ((CSCommon.eSocialType)type == CSCommon.eSocialType.Friend)
                {
                    //发送消息
                    CSCommon.Data.Message msg = CreateMessage(CSCommon.eMessageFrom.Social, _GetSocialMsgType((CSCommon.eSocialType)type), role.RoleData.Name, other.RoleData.RoleId);
                    msg.ShowInfo = string.Format("玩家{0}把你加为好友", role.RoleData.Name);
                    SendMessageToOther(other, msg);
                }
            }
            pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
        }
Ejemplo n.º 6
0
 public Social(CSCommon.Data.SocialData data)
 {
     mSocialData = data;
 }
Ejemplo n.º 7
0
        // 生成代码
        private void button4_Click(object sender, EventArgs e)
        {
            bool bIsClient = this.textBox_Callee.Text == Config.Instance.CurProjectConfig.ClientCallee;

            if (System.IO.File.Exists(this.textBox_Callee.Text))
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(this.textBox_Callee.Text);
                if (sw != null)
                {
                    if (bIsClient)
                    {
                        sw.Write(this.textBoxCallee.Text.Replace("SlimDX", "UnityEngine"));
                    }
                    else
                    {
                        sw.Write(this.textBoxCallee.Text);
                    }
                    sw.Close();
                }
            }

            if (System.IO.File.Exists(this.textBox_Caller.Text))
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(this.textBox_Caller.Text);
                if (sw != null)
                {
                    if (bIsClient)
                    {
                        sw.Write(this.textBoxCaller.Text.Replace("SlimDX", "UnityEngine"));
                    }
                    else
                    {
                        sw.Write(this.textBoxCaller.Text);
                    }
                    sw.Close();
                }
            }

            if (bIsClient)
            {
                if (System.IO.File.Exists(Config.Instance.CurProjectConfig.ServCppCaller))
                {
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(Config.Instance.CurProjectConfig.ServCppCaller);
                    if (sw != null)
                    {
                        sw.Write(this.textBoxCaller.Text.Replace("UnityEngine", "SlimDX"));
                        sw.Close();
                    }
                }
            }
            else
            {
                if (System.IO.File.Exists(Config.Instance.CurProjectConfig.ClientServCaller))
                {
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(Config.Instance.CurProjectConfig.ClientServCaller);
                    if (sw != null)
                    {
                        sw.Write(ServCallerToClient.Replace("SlimDX", "UnityEngine"));
                        sw.Close();
                    }
                }
            }

            //====================== 客户端同步服务器的类结构 ======================

            string outStruct = "";

            //GetCppStructureDefine只发送基础属性 byte[] x = new byte[3], list<int> y = new list<int>();类似属性都将不发送
            outStruct += new CSCommon.Data.RoleInfo().GetCppStructureDefine();
            outStruct += new CSCommon.Data.NPCData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.RoleDetail().GetCppStructureDefine();
            outStruct += new CSCommon.Data.RoleSyncInfo().GetCppStructureDefine();
            outStruct += new CSCommon.Data.ItemData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.SocialData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.SocialRoleInfo().GetCppStructureDefine();
            outStruct += new CSCommon.Data.GiftData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.TaskData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.MailData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.GuildCom().GetCppStructureDefine();
            outStruct += new CSCommon.Data.RoleCom().GetCppStructureDefine();
            outStruct += new CSCommon.Data.Message().GetCppStructureDefine();
            outStruct += new CSCommon.Data.SkillData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.MartialData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.AchieveData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.AttrStruct().GetCppStructureDefine();
            outStruct += new CSCommon.Data.CityForceData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.EfficiencyData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.CampForceData().GetCppStructureDefine();
            //===================================================================

            if (System.IO.File.Exists(Config.Instance.CurProjectConfig.ClientHeader))
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(Config.Instance.CurProjectConfig.ClientHeader);
                if (sw != null)
                {
                    sw.Write(outStruct);
                    sw.Close();
                }
            }
        }