public void CreateNewPost(byte[] argument, uint u) { byte[] threadIdBytes = new byte[4]; byte[] usernameBytes = new byte[16]; byte[] postTitleBytes = new byte[36]; byte[] postBodyBytes = new byte[600]; Buffer.BlockCopy(argument, 0, threadIdBytes, 0, 4); Buffer.BlockCopy(argument, 4, usernameBytes, 0, 16); Buffer.BlockCopy(argument, 84, postTitleBytes, 0, 32); Buffer.BlockCopy(argument, 134, postBodyBytes, 0, 600); Console.WriteLine("Thread ID = " + BitConverter.ToString(threadIdBytes)); Console.WriteLine("username " + BitConverter.ToString(usernameBytes)); Console.WriteLine("post Title " + BitConverter.ToString(postTitleBytes)); Console.WriteLine("post Body " + BitConverter.ToString(postBodyBytes)); // int threadIDX = BitConverter.ToInt32(threadIdBytes); String username = _encoding.GetString(usernameBytes); String postTitle = _encoding.GetString(postTitleBytes); String postBody = _encoding.GetString(postBodyBytes); int threadID = 0; if (u == 0) { // Create a new Thread before posting BbsThreadModel thread = new BbsThreadModel(); thread.threadTitle = postTitleBytes; thread.categoryID = 1; using (ISession session = _sessionFactory.OpenSession()) { //threadID = session.Query<BbsThreadModel>().Max(x => (int?) x.threadID).Value + 1; //thread.threadID = threadID; using (ITransaction transaction = session.BeginTransaction()) { session.Save(thread); transaction.Commit(); threadID = thread.threadID; } session.Close(); } } else { threadID = Convert.ToInt32(u); } // post to an existing thread BbsPostMetaModel meta = new BbsPostMetaModel(); meta.unk2 = 0; meta.date = DateTime.UtcNow; meta.username = usernameBytes; meta.title = postTitleBytes; meta.subtitle = new byte[16]; if (postTitle.Length > 16) { Buffer.BlockCopy(postTitleBytes, 0, meta.subtitle, 0, 16); } else { meta.subtitle = postTitleBytes; } meta.unk3 = "unk3"; meta.threadID = threadID; using (ISession session = _sessionFactory.OpenSession()) { try { meta.unk0 = session.Query <BbsPostMetaModel>().Max(x => (int?)x.unk0).Value + 1; } catch (Exception) { Console.WriteLine("BBS is empty , creating needed data"); meta.unk0 = 1; } //int postBodyID = session.Query<BbsPostBody>().Max(x => (int?) x.postBodyID).Value + 1; //meta.postID = postID; using (ITransaction transaction = session.BeginTransaction()) { session.Save(meta); //transaction.Commit(); BbsPostBody body = new BbsPostBody(); body.postBody = postBodyBytes; body.postID = meta.postID; session.Save(body); transaction.Commit(); } session.Close(); } // Console.WriteLine("Thread ID = " + threadIDX); Console.WriteLine("username " + username); Console.WriteLine("post Title " + postTitle); Console.WriteLine("post Body " + postBody); }
public async Task <byte[]> ConvertThreadDetailsToBytesAsync(BbsPostMetaModel postMetaModel) { const int MAX_USERNAME_LENGTH = 16; const int MAX_SUBTITLE_LENGTH = 17; const int MAX_TITLE_LENGTH = 32; var m = new MemoryStream(); await m.WriteAsync(BitConverter.GetBytes(swap32((uint)postMetaModel.unk0)), 0, 4); //unk await m.WriteAsync(BitConverter.GetBytes(swap32((uint)postMetaModel.postID)), 0, 4); //postid await m.WriteAsync(BitConverter.GetBytes(swap32((uint)postMetaModel.unk2)), 0, 4); //unk2 TimeSpan t = postMetaModel.date - new DateTime(1970, 1, 1); int secondsSinceEpoch = (int)t.TotalSeconds; await m.WriteAsync(BitConverter.GetBytes(swap32((uint)secondsSinceEpoch)), 0, 4); //date // Setting the username if (postMetaModel.username.Length > MAX_USERNAME_LENGTH) { byte[] temp = new byte[MAX_USERNAME_LENGTH]; Buffer.BlockCopy(postMetaModel.username, 0, temp, 0, MAX_USERNAME_LENGTH); postMetaModel.username = temp; } byte[] usernameBytes = postMetaModel.username; await m.WriteAsync(usernameBytes, 0, usernameBytes.Length); //username while (m.Length < 0x20) { m.WriteByte(0); } //setting the Subtitle if (postMetaModel.subtitle.Length > MAX_SUBTITLE_LENGTH) { byte[] temp = new byte[MAX_SUBTITLE_LENGTH]; Buffer.BlockCopy(postMetaModel.subtitle, 0, temp, 0, MAX_SUBTITLE_LENGTH); postMetaModel.subtitle = temp; } byte[] subtitleBytes = postMetaModel.subtitle; await m.WriteAsync(subtitleBytes, 0, subtitleBytes.Length); // subtitles while (m.Length < 0x32) { m.WriteByte(0); } //setting unk3 if (postMetaModel.unk3.Length > 45) { postMetaModel.unk3 = postMetaModel.unk3.Substring(0, 45); } byte[] unk3Bytes = encoding.GetBytes(postMetaModel.unk3); await m.WriteAsync(unk3Bytes, 0, unk3Bytes.Length); while (m.Length < 0x60) { m.WriteByte(0); } //setting the title if (postMetaModel.title.Length > MAX_TITLE_LENGTH) { byte[] temp = new byte[MAX_TITLE_LENGTH]; Buffer.BlockCopy(postMetaModel.title, 0, temp, 0, MAX_TITLE_LENGTH); postMetaModel.title = temp; } byte[] titleBytes = postMetaModel.title; await m.WriteAsync(titleBytes, 0, titleBytes.Length); // title while (m.Length < 0x80) { m.WriteByte(0); } return(m.ToArray()); }