Ejemplo n.º 1
0
 /// <summary>
 /// 将基础类转为BYTE字节
 /// </summary>
 /// <param name="bm"></param>
 /// <returns></returns>
 public byte[] Get_Byte(WeaveSession bm)
 {
     byte[] b    = bm.GetRoot <byte[]>();
     byte[] data = new byte[2 + b.Length];
     byte[] req  = new byte[0];
     if (bm.Request == "getdata")
     {
         req = ConvertToByteList(256);
     }
     if (req.Length == 2)
     {
         data[0] = req[0];
         data[1] = req[1];
     }
     if (req.Length < 2)
     {
         data[0] = 0;
         data[1] = req[1];
     }
     Array.Copy(b, 0, data, 2, b.Length);
     return(data);
 }
        public void CheckLogin(Socket soc, WeaveSession wsession)
        {
            // string jsonstr = _0x01.Getjson();
            LoginTempModel get_client_Send_loginModel = wsession.GetRoot <LoginTempModel>();



            //执行查找数据的操作......
            bool loginOk = false;


            AddSystemData();

            loginOk = CheckUserCanLoginIn(get_client_Send_loginModel);
            if (loginOk)
            {
                // UpdatePlayerListSetOnLine
                ServerLoginOKEvent(get_client_Send_loginModel.userName, soc);
            }
            SendRoot <bool>(soc, (byte)CommandEnum.ServerSendLoginResult, "ServerBackLoginResult", loginOk, 0, wsession.Token);
            //发送人数给客户端
            //参数1,发送给客户端对象,参数2,发送给客户端对应的方法,参数3,人数的实例,参数4,此处无作用,参数5,客户端此次token
        }
Ejemplo n.º 3
0
        public void SaveFile(Socket soc, WeaveSession _0x01)
        {
            filestream fstream = _0x01.GetRoot <filestream>();


lb0330:
            if (File.Exists(_0x01.Token + "/" + fstream.Filename + ".tmp"))
            {
                System.IO.FileStream fi = System.IO.File.Open(_0x01.Token + "/" + fstream.Filename + ".tmp", FileMode.Open, FileAccess.Write, FileShare.Write);
                fi.Seek(fstream.Index * 1024 * 4, SeekOrigin.Begin);
                fi.Write(fstream.Stream, 0, fstream.Len);
                fi.Close();
                var fstate = listfilestate.Where(f => f.Filename == fstream.Filename);
                foreach (filestate fst in fstate)
                {
                    fst.Dt = DateTime.Now;
                    fst.State[fstream.Index] = 1;
                }
            }
            else
            {
                System.Threading.Thread.Sleep(100); goto lb0330;
            }
        }
Ejemplo n.º 4
0
 [InstallFun("forever")]//这是一个接收的方法,注册到了通讯类中
 public void getdata(Socket soc, WeaveSession _0x01)
 {
     SendRoot <byte[]>(soc, 0x01, "getdata", _0x01.GetRoot <byte[]>(), 0, "随便我没用到");
 }
Ejemplo n.º 5
0
        public void check(Socket soc, WeaveSession _0x01)
        {
            filestream fstream = _0x01.GetRoot <filestream>();
            var        fstate  = listfilestate.Where(f => f.Filename == fstream.Filename);

            foreach (filestate fst in fstate)
            {
                int sumlen = 0;
                foreach (byte b in fst.State)
                {
                    sumlen += b;
                }
                if (sumlen >= fst.State.Length)
                {
                    try
                    {
                        if (fstream.Filetype != "")
                        {
                            if (!Directory.Exists(@trsqfilepath + @"\" + fstream.Filetype))         //如果不存在就创建file文件夹                 
                            {
                                Directory.CreateDirectory(@trsqfilepath + @"\" + fstream.Filetype); //创建该文件夹  

                                File.Move(@basepath + @"\" + fst.Path + @"\" + fst.Filename + ".tmp", @trsqfilepath + @"\" + fstream.Filetype + @"\" + fst.Filename);
                            }
                            else
                            {
                                File.Move(@basepath + @"\" + fst.Path + @"\" + fst.Filename + ".tmp", @trsqfilepath + @"\" + fstream.Filetype + @"\" + fst.Filename);
                            }
                        }
                        else
                        {
                            File.Move(@basepath + @"\" + fst.Path + @"\" + fst.Filename + ".tmp", @filepath + @"\" + fst.Filename);
                        }
                    }
                    catch (Exception ex) {
                        {
                            using (StreamWriter sw = new StreamWriter(@basepath + "\\log\\接收.txt"))
                            {
                                sw.WriteLine(ex.ToString());
                                sw.Close();
                            }
                        }
                    }
                    try
                    {
                        File.Delete(@basepath + @"\" + fst.Path + @"\" + fst.Filename + ".tmp");
                    }
                    catch { }
                    listfilestate.Remove(fst);
                    if (!SendRoot <string>(soc, 0x31, "finish", fst.Filename, 0, "finish"))
                    {
                    }
                    return;
                }
                else if ((DateTime.Now - fst.Dt).TotalSeconds > 5)
                {
                    for (int i = 0; i < fst.State.Length; i++)
                    {
                        if (fst.State[i] == 0)
                        {
                            filestream st = new filestream();
                            st.Filename = fst.Filename;
                            st.Index    = i;
                            if (!SendRoot <filestream>(soc, 0x31, "pushdata", st, 0, "pushdata"))
                            {
                                //listfilestate.Remove(fst);
                                //try
                                //{
                                //    File.Delete(@basepath + @"\" + fst.Path + @"\" + fst.Filename + ".tmp");
                                //}
                                //catch { }
                                return;
                            }
                        }
                    }
                    return;
                }
            }
            if (!SendRoot <string>(soc, 0x31, "finish", fstream.Filename, 0, "finish"))
            {
            }
        }