patch-add_file_c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. $OpenBSD: patch-add_file_c,v 1.2 2009/02/14 09:41:35 jasper Exp $
  2. --- add_file.c.orig Sat Sep 29 07:21:51 2001
  3. +++ add_file.c Sat Feb 14 10:40:49 2009
  4. @@ -233,6 +233,7 @@ sNewDatum (char *filename, char *hash)
  5. FREE (info);
  6. return 0;
  7. }
  8. + strlower (info->hash);
  9. #endif
  10. return info;
  11. }
  12. @@ -248,8 +249,8 @@ sBitrateToMask (int bitrate, USER * user)
  13. if (bitrate <= BitRate[i])
  14. return i;
  15. }
  16. - log_message ("sBitrateToMask(): invalid bit rate %d (%s, \"%s\")", bitrate,
  17. - user->nick, user->clientinfo);
  18. + log_message ("sBitrateToMask(): invalid bit rate %d (%s, \"%s\")",
  19. + bitrate, user->nick, user->clientinfo);
  20. return 0; /* invalid bitrate */
  21. }
  22. @@ -287,6 +288,8 @@ HANDLER (add_file)
  23. if (!option (ON_ALLOW_SHARE))
  24. return;
  25. + if(con->user->level==LEVEL_LEECH)
  26. + return;
  27. if (Max_Shared && con->user->shared >= Max_Shared)
  28. {
  29. @@ -376,6 +379,8 @@ HANDLER (share_file)
  30. if (!option (ON_ALLOW_SHARE))
  31. return;
  32. + if(con->user->level==LEVEL_LEECH)
  33. + return;
  34. if (Max_Shared && con->user->shared >= Max_Shared)
  35. {
  36. log_message ("add_file(): %s is already sharing %d files",
  37. @@ -466,6 +471,8 @@ HANDLER (add_directory)
  38. CHECK_USER_CLASS ("add_directory");
  39. if (!option (ON_ALLOW_SHARE))
  40. return;
  41. + if(con->user->level==LEVEL_LEECH)
  42. + return;
  43. dir = next_arg (&pkt); /* directory */
  44. if (!dir)
  45. {
  46. @@ -653,8 +660,40 @@ HANDLER (user_sharing)
  47. user->libsize);
  48. }
  49. +void
  50. +unshare_all_internal (USER * user)
  51. +{
  52. + if (user->shared)
  53. + {
  54. +#ifndef ROUTING_ONLY
  55. + if (ISUSER (user->con))
  56. + {
  57. + /* local user */
  58. + free_hash (user->con->uopt->files);
  59. + user->con->uopt->files = 0;
  60. + ASSERT (Local_Files >= user->shared);
  61. + Local_Files -= user->shared;
  62. + }
  63. +#endif /* !ROUTING_ONLY */
  64. + if (user->libsize > Num_Gigs)
  65. + {
  66. + log_message ("unshare_all: sender->libsize=%u Num_Gigs=%f",
  67. + user->libsize, Num_Gigs);
  68. + Num_Gigs = user->libsize;
  69. + }
  70. + ASSERT (Num_Gigs >= user->libsize);
  71. + Num_Gigs -= user->libsize;
  72. + ASSERT (Num_Files >= user->shared);
  73. + Num_Files -= user->shared;
  74. + user->libsize = 0;
  75. + user->shared = 0;
  76. + }
  77. +}
  78. +
  79. /* 110 [:sender]
  80. - * unshare all files
  81. + * unshare all files. this will handle the case of a remote server forcing
  82. + * a local client to unshare all files as well, so we can have the hub
  83. + * perform this action.
  84. */
  85. HANDLER (unshare_all)
  86. {
  87. @@ -664,33 +703,18 @@ HANDLER (unshare_all)
  88. (void) len;
  89. if (pop_user_server (con, tag, &pkt, &sender_name, &sender))
  90. return;
  91. - ASSERT (sender != 0);
  92. -#ifndef ROUTING_ONLY
  93. + if (!sender)
  94. + {
  95. + log_message ("unshare_all: error: received unshare message from server %s",
  96. + sender_name);
  97. + return;
  98. + }
  99. if (ISUSER (con))
  100. {
  101. - if (!con->uopt->files)
  102. - {
  103. - ASSERT (sender->shared == 0);
  104. - return; /* nothing shared */
  105. - }
  106. + if (sender->shared == 0)
  107. + return; /* nothing to unshare */
  108. send_cmd (con, tag, "%d", sender->shared);
  109. - free_hash (con->uopt->files);
  110. - con->uopt->files = 0;
  111. - ASSERT (Local_Files >= sender->shared);
  112. - Local_Files -= sender->shared;
  113. }
  114. -#endif /* !ROUTING_ONLY */
  115. - if (sender->libsize > Num_Gigs)
  116. - {
  117. - log_message ("unshare_all: sender->libsize=%u Num_Gigs=%f",
  118. - sender->libsize, Num_Gigs);
  119. - Num_Gigs = sender->libsize;
  120. - }
  121. - ASSERT (Num_Gigs >= sender->libsize);
  122. - Num_Gigs -= sender->libsize;
  123. - ASSERT (Num_Files >= sender->shared);
  124. - Num_Files -= sender->shared;
  125. - sender->libsize = 0;
  126. - sender->shared = 0;
  127. + unshare_all_internal (sender);
  128. pass_message_args (con, tag, ":%s", sender->nick);
  129. }