Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TForm1.ClientSocketRead(Sender: TObject;
- Socket: TCustomWinSocket);
- var NET_BUFF : string;
- NET_CODE : string;
- TMP_STR : string;
- TMP_LAST : string;
- av_key : word;
- pos_index : word;
- i,n : word;
- tmp_view_style : TViewStyle;
- begin
- NET_BUFF := Socket.ReceiveText();
- NET_CODE := copy(NET_BUFF,1,5);
- //ShowMessage(NET_BUFF);
- if NET_CODE = '^S^N:' then // N E W U S E R
- begin
- //Removing code chars:
- delete(NET_BUFF,1,5);
- //Playing notification sound:
- if (allow_snd=true) then PlaySound(PChar(snd_new_user),0,SND_ASYNC);
- userlist_view.Clear;
- //Main cycle:
- cl_userlist.DelimitedText:=NET_BUFF;
- for i:=0 to cl_userlist.Count-1 do
- begin
- //Saving current username to temporary string:
- TMP_STR:=cl_userlist.Strings[i];
- if (i=cl_userlist.Count-1) then TMP_LAST:=cl_userlist.Strings[i];
- //Storing av_key of the new user:
- if (pos('#A:',TMP_STR))<>0 then
- begin
- pos_index:=(pos('#A:',TMP_STR));
- av_key:=StrToInt(copy(TMP_STR,pos_index+3,1));
- //Removing avatar key:
- delete(TMP_STR,pos('#A:',TMP_STR),4);
- //Adding user to the userlist:
- userlist_view.AddItem(TMP_STR,nil);
- userlist_view.Items.Item[userlist_view.Items.count-1].ImageIndex:=av_key;
- end else //if unknown error:
- begin
- Socket.SendText('^D:'+u_name+cl_avatar_key);
- Socket.Close;
- showMessage('Error receiving a socket. Please contact the support.');
- Break;
- end;
- end;
- //Removing av_key from the last connected user:
- delete(TMP_LAST,pos('#A:',TMP_LAST),4);
- //Adding LAST user notification into the chat window:
- w_out.lines.Add(cl_msg_header+TMP_LAST+' - connected to the server.');
- end else
- if NET_CODE = '^S^M:' then // M E S S A G E
- begin
- delete(NET_BUFF,1,5);
- if (allow_snd=true) then PlaySound(PChar(snd_msg_in),0,SND_ASYNC);
- if (pos('Server message:',NET_BUFF)>0) then
- begin
- w_out.SelLength:=14;
- w_out.SelAttributes.Color:=clRed;
- end else w_out.SelAttributes.Color:=clDefault;
- if not (Showing) and (tray_message=true) then
- begin
- tray.ShowBalloonHint('-New message-',(cl_msg_header+NET_BUFF),bitInfo,10);
- tray.IconList:=tray_msg;
- tray.CycleIcons:=true;
- end;
- w_out.Lines.Add(cl_msg_header+NET_BUFF);
- //Scroll fix:
- SendMessage(w_out.Handle, EM_SCROLL, SB_LINEDOWN, 0);
- end else
- if (NET_CODE = '^S^D:') then // D I S C O N N E C T \ K I C K \ O F F L I N E
- begin
- delete(NET_BUFF,1,5);
- if (NET_BUFF=u_name+cl_avatar_key) then //if you was kicked
- begin
- clientsocket.Active:=false;
- w_out.Lines.Add(cl_msg_header+' - You have been kicked from the server by Administrator.');
- //Scroll fix:
- SendMessage(w_out.Handle, EM_SCROLL, SB_LINEDOWN, 0);
- end else
- begin
- //finding avatar_key:
- delete(NET_BUFF,pos('#A:',NET_BUFF),(Length(NET_BUFF)-pos('#A:',NET_BUFF)+1));
- //removing disconnected user from userlist:
- n := userlist_view.Items.IndexOf(userlist_view.FindCaption(0,NET_BUFF,true,true,false));
- if (n <> -1) then userlist_view.items.delete(n);
- //userlist-fix:
- tmp_view_style:=userlist_view.ViewStyle;
- userlist_view.ViewStyle:=vsList;
- userlist_view.ViewStyle:=tmp_view_style;
- end;
- end else
- if (NET_CODE = '^S^T:') then // T Y P I N G {begin}
- begin //-KEY_DOWN-
- delete(NET_BUFF,1,5);
- //Saving target avatar:
- t_indx:=StrToInt(Copy(NET_BUFF,pos('#A:',NET_BUFF)+3,(Length(NET_BUFF)-pos('#A:',NET_BUFF))+3) );
- //Changing target avatar:
- TMP_STR2:=Copy(NET_BUFF,0,pos('#A:',NET_BUFF)-1);
- n := userlist_view.Items.IndexOf(userlist_view.FindCaption(0,TMP_STR2,true,true,false));
- if (n <> -1) then userlist_view.items.Item[n].ImageIndex:=11;
- end else
- if (NET_CODE = '^S^S:') then // T Y P I N G {end}
- begin //-KEY_UP-
- delete(NET_BUFF,1,5);
- timer_type.Enabled:=false;
- timer_type.Enabled:=true;
- end;
- timer_fix_out.Enabled:=true;
- end;
Add Comment
Please, Sign In to add comment